Zelda Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2023-11-12 03:48:08
Exec Total Coverage
Lines: 1682 4267 39.4%
Functions: 132 333 39.6%
Branches: 933 3034 30.8%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro5/joystick.h"
5 #include "base/qrs.h"
6 #include "base/dmap.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <cstring>
10 #include <math.h>
11 #include <map>
12 #include <filesystem>
13 #include <ctype.h>
14 #include <sstream>
15 #include "base/version.h"
16 #include "base/zc_alleg.h"
17 #include "gamedata.h"
18 #include "zc/zc_init.h"
19 #include "init.h"
20 #include "zc/replay.h"
21 #include "zc/cheats.h"
22 #include "zc/render.h"
23 #include "base/zc_math.h"
24 #include "base/zapp.h"
25 #include "dialog/cheatkeys.h"
26 #include "metadata/metadata.h"
27 #include "zc/zelda.h"
28 #include "zc/saves.h"
29 #include "tiles.h"
30 #include "base/colors.h"
31 #include "pal.h"
32 #include "base/zsys.h"
33 #include "qst.h"
34 #include "zc/zc_sys.h"
35 #include "play_midi.h"
36 #include "gui/jwin_a5.h"
37 #include "base/jwinfsel.h"
38 #include "base/gui.h"
39 #include "midi.h"
40 #include "subscr.h"
41 #include "zc/maps.h"
42 #include "sprite.h"
43 #include "zc/guys.h"
44 #include "zc/hero.h"
45 #include "zc/title.h"
46 #include "particles.h"
47 #include "sound/zcmusic.h"
48 #include "zconsole.h"
49 #include "zc/ffscript.h"
50 #include "dialog/info.h"
51 #include "dialog/alert.h"
52 #include "zc/combos.h"
53 #include "zc/jit.h"
54 #include "zc/zc_subscr.h"
55 #include <fmt/format.h>
56 #include "zinfo.h"
57 #include "base/misctypes.h"
58 #include "music_playback.h"
59
60 #ifdef __EMSCRIPTEN__
61 #include "base/emscripten_utils.h"
62 #endif
63
64 using namespace std::chrono_literals;
65
66 extern FFScript FFCore;
67 extern bool Playing;
68 int32_t sfx_voice[WAV_COUNT];
69 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
70 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
71
72 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
73 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
74
75 extern byte monochrome_console;
76
77 extern HeroClass Hero;
78 extern zcmodule moduledata;
79 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
80 extern particle_list particles;
81 extern int32_t loadlast;
82 extern char *sfx_string[WAV_COUNT];
83 byte use_dwm_flush;
84 byte use_save_indicator;
85 int32_t paused_midi_pos = 0;
86 byte midi_suspended = 0;
87 byte zc_192b163_warp_compatibility;
88 char modulepath[2048];
89 bool epilepsyFlashReduction;
90 signed char pause_in_background_menu_init = 0;
91 byte pause_in_background = 0;
92 bool is_sys_pal = false;
93 static bool load_control_called_this_frame;
94 extern PALETTE* hw_palette;
95 extern bool update_hw_pal;
96 extern const char* dmaplist(int32_t index, int32_t* list_size);
97 int32_t getnumber(const char *prompt,int32_t initialval);
98
99 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
100 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
101
102 static const char *qst_module_name = "current_module";
103 #ifdef ALLEGRO_LINUX
104 static const char *samplepath = "samplesoundset/patches.dat";
105 #endif
106 char qst_files_path[2048];
107
108 #ifdef _MSC_VER
109 #define getcwd _getcwd
110 #endif
111
112 bool rF11();
113 bool rI();
114 bool rQ();
115 bool zc_key_pressed();
116
117 #ifdef _WIN32
118
119 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
120 extern "C"
121 {
122 typedef HRESULT(WINAPI *t_DwmFlush)();
123 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
124 }
125
126 void do_DwmFlush()
127 {
128 static HMODULE shell = LoadLibrary("dwmapi.dll");
129
130 if(!shell)
131 return;
132
133 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
134 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
135
136 BOOL enabled;
137 isEnabled(&enabled);
138
139 if(isEnabled)
140 flush();
141 }
142
143 #endif // _WIN32
144
145 83751 bool flash_reduction_enabled(bool check_qr)
146 {
147
4/4
✓ Branch 0 taken 81530 times.
✓ Branch 1 taken 2221 times.
✓ Branch 2 taken 81074 times.
✓ Branch 3 taken 83295 times.
83751 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
148 }
149
150 // Dialogue largening
151 void large_dialog(DIALOG *d)
152 {
153 large_dialog(d, 1.5);
154 }
155
156 void large_dialog(DIALOG *d, float RESIZE_AMT)
157 {
158 if(!d[0].d1)
159 {
160 d[0].d1 = 1;
161 int32_t oldwidth = d[0].w;
162 int32_t oldheight = d[0].h;
163 int32_t oldx = d[0].x;
164 int32_t oldy = d[0].y;
165 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
166 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
167 d[0].w = int32_t(d[0].w*RESIZE_AMT);
168 d[0].h = int32_t(d[0].h*RESIZE_AMT);
169
170 for(int32_t i=1; d[i].proc !=NULL; i++)
171 {
172 // Place elements horizontally
173 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
174 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
175
176 if(d[i].proc != d_stringloader)
177 {
178 if(d[i].proc==d_bitmap_proc)
179 {
180 d[i].w *= 2;
181 }
182 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
183 }
184
185 // Place elements vertically
186 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
187 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
188
189 // Vertically resize elements
190 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
191 {
192 d[i].h = int32_t((double)d[i].h*1.5);
193 }
194 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
195 {
196 d[i].y += int32_t((double)d[i].h*0.25);
197 d[i].h = int32_t((double)d[i].h*1.25);
198 }
199 else if(d[i].proc==d_bitmap_proc)
200 {
201 d[i].h *= 2;
202 }
203 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
204
205 // Fix frames
206 if(d[i].proc == jwin_frame_proc)
207 {
208 d[i].x++;
209 d[i].y++;
210 d[i].w-=4;
211 d[i].h-=4;
212 }
213 }
214 }
215
216 for(int32_t i=1; d[i].proc!=NULL; i++)
217 {
218 if(d[i].proc==jwin_slider_proc)
219 continue;
220
221 // Bigger font
222 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
223
224 if(!d[i].dp2 && bigfontproc)
225 {
226 d[i].dp2 = get_zc_font(font_lfont_l);
227 }
228 else if(!bigfontproc)
229 {
230 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
231 }
232
233 // Make checkboxes work
234 if(d[i].proc == jwin_check_proc)
235 d[i].proc = jwin_checkfont_proc;
236 else if(d[i].proc == jwin_radio_proc)
237 d[i].proc = jwin_radiofont_proc;
238 }
239
240 jwin_center_dialog(d);
241 }
242
243
244 /**********************************/
245 /******** System functions ********/
246 /**********************************/
247
248 static char cfg_sect[] = "zeldadx"; //We need to rename this.
249 static char ctrl_sect[] = "Controls";
250 static char sfx_sect[] = "Volume";
251
252 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
253 {
254 return D_O_K;
255 }
256
257 bool is_reserved_key(int c)
258 {
259 switch(c)
260 {
261 case KEY_ESC:
262 return true;
263 }
264 return false;
265 }
266 bool is_reserved_keycombo(int c, int modflag)
267 {
268 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
269 return true;
270 return false;
271 }
272 bool checkcheat(Cheat cheat)
273 {
274 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
275 return true; //Main key pressed
276 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
277 return true; //Alt key pressed
278 return false;
279 }
280 117 void load_default_cheatkeys()
281 {
282 117 memset(cheatkeys, 0, sizeof(cheatkeys));
283 117 cheatkeys[Cheat::Life][0] = KEY_H;
284 117 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
285 117 cheatkeys[Cheat::Magic][0] = KEY_M;
286 117 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
287 117 cheatkeys[Cheat::Rupies][0] = KEY_R;
288 117 cheatkeys[Cheat::Bombs][0] = KEY_B;
289 117 cheatkeys[Cheat::Arrows][0] = KEY_A;
290 117 cheatkeys[Cheat::Clock][0] = KEY_I;
291 117 cheatkeys[Cheat::Walls][0] = KEY_F11;
292 117 cheatkeys[Cheat::Fast][0] = KEY_Q;
293 117 cheatkeys[Cheat::Light][0] = KEY_L;
294 117 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
295 117 cheatkeys[Cheat::Kill][0] = KEY_K;
296 117 cheatkeys[Cheat::GoTo][0] = KEY_G;
297 117 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
298 117 cheatkeys[Cheat::ShowL0][0] = KEY_0;
299 117 cheatkeys[Cheat::ShowL1][0] = KEY_1;
300 117 cheatkeys[Cheat::ShowL2][0] = KEY_2;
301 117 cheatkeys[Cheat::ShowL3][0] = KEY_3;
302 117 cheatkeys[Cheat::ShowL4][0] = KEY_4;
303 117 cheatkeys[Cheat::ShowL5][0] = KEY_5;
304 117 cheatkeys[Cheat::ShowL6][0] = KEY_6;
305 117 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
306 117 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
307 117 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
308 117 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
309 117 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
310 117 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
311 117 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
312 117 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
313 117 }
314 117 void load_game_configs()
315 {
316 117 strcpy(moduledata.module_name,zc_get_config("ZCMODULE",qst_module_name,"classic.zmod"));
317 117 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
318 117 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
319 117 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
320 117 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
321 117 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
322 117 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
323 117 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
324 117 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
325 117 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
326 117 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
327 117 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
328 117 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
329 117 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
330 117 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
331
332 //cheat modifier keya
333 117 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
334 117 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
335 117 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
336 117 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
337
338 //cheat keys
339 117 load_default_cheatkeys();
340 char buf[256];
341
2/2
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 4095 times.
4212 for(size_t q = 1; q < Cheat::Last; ++q)
342 {
343
1/2
✓ Branch 0 taken 4095 times.
✗ Branch 1 not taken.
4095 if(!bindable_cheat((Cheat)q)) continue;
344 4095 std::string cheatname = cheat_to_string((Cheat)q);
345
1/2
✓ Branch 0 taken 4095 times.
✗ Branch 1 not taken.
4095 util::lowerstr(cheatname);
346 4095 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
347
1/2
✓ Branch 0 taken 4095 times.
✗ Branch 1 not taken.
4095 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
348 4095 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
349
1/2
✓ Branch 0 taken 4095 times.
✗ Branch 1 not taken.
4095 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
350 4095 }
351
352
1/2
✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
117 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
353 joystick_index = 0;
354
355 117 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
356 117 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
357 117 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
358 117 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
359 117 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
360 117 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
361 117 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
362 117 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
363 117 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
364 117 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
365
366 117 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
367 117 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
368 117 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
369 117 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
370
371 117 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
372 117 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
373 117 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
374 117 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
375 117 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
376 117 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
377 117 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
378 117 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
379 117 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
380 117 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
381 117 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
382
383 117 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
384 117 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
385 117 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
386 117 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
387
388 117 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
389
390 117 digi_volume = zc_get_config(sfx_sect,"digi",248);
391 117 midi_volume = zc_get_config(sfx_sect,"midi",255);
392 117 sfx_volume = zc_get_config(sfx_sect,"sfx",248);
393 117 emusic_volume = zc_get_config(sfx_sect,"emusic",248);
394 117 pan_style = zc_get_config(sfx_sect,"pan",1);
395 // 1 <= zcmusic_bufsz <= 128
396 117 zcmusic_bufsz = vbound(zc_get_config(sfx_sect,"zcmusic_bufsz",64),1,128);
397 117 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
398 117 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
399 117 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
400 117 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
401 117 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
402 117 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
403 117 SnapshotScale = zc_get_config(cfg_sect,"snapshot_scale",2);
404 117 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
405 #ifdef __EMSCRIPTEN__
406 if (em_is_mobile()) NameEntryMode = 2;
407 #endif
408 117 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
409 117 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
410 117 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
411 117 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
412 117 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
413
414 117 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
415 117 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
416 117 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
417 117 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
418 117 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
419 117 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
420 117 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
421
422 117 loadlast = zc_get_config(cfg_sect,"load_last",0);
423
424 117 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
425
426 117 zc_color_depth = (byte) zc_get_config(cfg_sect,"color_depth",8);
427
428 117 forceExit = (byte) zc_get_config(cfg_sect,"force_exit",0);
429 117 info_opacity = zc_get_config("zc","debug_info_opacity",255);
430 #ifdef _WIN32
431 zasm_debugger = (byte) zc_get_config("CONSOLE","print_ZASM",0);
432 zscript_debugger = (byte) zc_get_config("CONSOLE","ZScript_Debugger",0);
433 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
434 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
435
436 // This one's for Aero
437 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
438
439 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
440 #else //UNIX
441 117 zasm_debugger = (byte) zc_get_config("CONSOLE","print_ZASM",0);
442 117 zscript_debugger = (byte) zc_get_config("CONSOLE","ZScript_Debugger",0);
443 117 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
444 #endif
445 117 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
446 117 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
447
448 117 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
449 117 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
450 117 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
451 117 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
452 117 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
453 117 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
454 117 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
455 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
456 117 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1);
457 117 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
458 117 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
459 117 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
460 117 }
461
462 void save_control_configs(bool kb)
463 {
464 if(kb)
465 {
466 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
467 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
468 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
469 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
470
471 if (!replay_is_replaying())
472 {
473 zc_set_config(ctrl_sect,"key_a",Akey);
474 zc_set_config(ctrl_sect,"key_b",Bkey);
475 zc_set_config(ctrl_sect,"key_s",Skey);
476 zc_set_config(ctrl_sect,"key_l",Lkey);
477 zc_set_config(ctrl_sect,"key_r",Rkey);
478 zc_set_config(ctrl_sect,"key_p",Pkey);
479 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
480 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
481 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
482 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
483 zc_set_config(ctrl_sect,"key_up", DUkey);
484 zc_set_config(ctrl_sect,"key_down", DDkey);
485 zc_set_config(ctrl_sect,"key_left", DLkey);
486 zc_set_config(ctrl_sect,"key_right",DRkey);
487 }
488 }
489 else
490 {
491 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
492 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
493 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
494 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
495 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
496 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
497 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
498 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
499 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
500 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
501 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
502 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
503 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
504 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
505
506 zc_set_config(ctrl_sect,"btn_a",Abtn);
507 zc_set_config(ctrl_sect,"btn_b",Bbtn);
508 zc_set_config(ctrl_sect,"btn_s",Sbtn);
509 zc_set_config(ctrl_sect,"btn_m",Mbtn);
510 zc_set_config(ctrl_sect,"btn_l",Lbtn);
511 zc_set_config(ctrl_sect,"btn_r",Rbtn);
512 zc_set_config(ctrl_sect,"btn_p",Pbtn);
513 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
514 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
515 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
516 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
517
518 zc_set_config(ctrl_sect,"btn_up",DUbtn);
519 zc_set_config(ctrl_sect,"btn_down",DDbtn);
520 zc_set_config(ctrl_sect,"btn_left",DLbtn);
521 zc_set_config(ctrl_sect,"btn_right",DRbtn);
522 }
523 }
524
525 void save_cheatkeys()
526 {
527 char buf[256];
528 for(size_t q = 1; q < Cheat::Last; ++q)
529 {
530 if(!bindable_cheat((Cheat)q)) continue;
531 std::string cheatname = cheat_to_string((Cheat)q);
532 util::lowerstr(cheatname);
533 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
534 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
535 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
536 if(cheatkeys[q][1])
537 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
538 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
539 }
540 }
541
542 void save_game_configs()
543 {
544 packfile_password("");
545
546 zc_set_config("ZCMODULE",qst_module_name,moduledata.module_name);
547
548 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
549 {
550 int o_window_x, o_window_y;
551 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
552 zc_set_config(cfg_sect,"window_x",o_window_x);
553 zc_set_config(cfg_sect,"window_y",o_window_y);
554 }
555
556 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
557 {
558 window_width = al_get_display_width(all_get_display());
559 window_height = al_get_display_height(all_get_display());
560 zc_set_config(cfg_sect,"window_width",window_width);
561 zc_set_config(cfg_sect,"window_height",window_height);
562 }
563
564 zc_set_config(cfg_sect,"load_last",loadlast);
565 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
566
567 flush_config_file();
568 #ifdef __EMSCRIPTEN__
569 em_sync_fs();
570 #endif
571 }
572
573 //----------------------------------------------------------------
574
575 // Timers
576
577 32311 void fps_callback()
578 {
579 32311 lastfps=framecnt;
580 32311 framecnt=0;
581 32311 }
582
583 END_OF_FUNCTION(fps_callback)
584
585 117 int32_t Z_init_timers()
586 {
587 static bool didit = false;
588 const static char *err_str = "Couldn't allocate timer";
589 117 err_str = err_str; //Unused variable warning
590
591
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
117 if(didit)
592 return 1;
593
594 117 didit = true;
595
596 LOCK_VARIABLE(lastfps);
597 LOCK_VARIABLE(framecnt);
598 LOCK_FUNCTION(fps_callback);
599
600
1/2
✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
117 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
601 return 0;
602
603 117 return 1;
604 117 }
605
606 void Z_remove_timers()
607 {
608 remove_int(fps_callback);
609 }
610
611 //----------------------------------------------------------------
612
613 void go()
614 {
615 blit(screen,tmp_scr,scrx,scry,0,0,screen->w,screen->h);
616 }
617
618 void comeback()
619 {
620 blit(tmp_scr,screen,0,0,scrx,scry,screen->w,screen->h);
621 }
622
623 void dump_pal(BITMAP *dest)
624 {
625 for(int32_t i=0; i<256; i++)
626 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
627 }
628
629 //----------------------------------------------------------------
630
631 int game_mouse_index = ZCM_BLANK;
632 static bool system_mouse = false;
633 28 bool sys_mouse()
634 {
635 28 system_mouse = true;
636 28 return MouseSprite::set(ZCM_NORMAL);
637 }
638 561 bool game_mouse()
639 {
640 561 system_mouse = false;
641 561 return MouseSprite::set(game_mouse_index);
642 }
643 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
644 {
645 if(!bmp)
646 return;
647 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
648 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
649 if(bmp->w == scaledw && bmp->h == scaledh)
650 user_scale = false;
651 if(user_scale || sys_recolor)
652 {
653 if(!user_scale) scale = 1;
654 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
655 if(user_scale)
656 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
657 else
658 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
659 if(sys_recolor)
660 recolor_mouse(tmpbmp);
661 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
662 destroy_bitmap(tmpbmp);
663 }
664 else
665 {
666 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
667 }
668 }
669
670 //Handles converting the mouse sprite from the .dat file
671 void recolor_mouse(BITMAP* bmp)
672 {
673 for(int32_t x = 0; x < bmp->w; ++x)
674 {
675 for(int32_t y = 0; y < bmp->h; ++y)
676 {
677 int32_t color = getpixel(bmp, x, y);
678 switch(color)
679 {
680 case dvc(1):
681 color = jwin_pal[jcCURSORMISC];
682 break;
683 case dvc(2):
684 color = jwin_pal[jcCURSOROUTLINE];
685 break;
686 case dvc(3):
687 color = jwin_pal[jcCURSORLIGHT];
688 break;
689 case dvc(5):
690 color = jwin_pal[jcCURSORDARK];
691 break;
692 default:
693 continue;
694 }
695 putpixel(bmp, x, y, color);
696 }
697 }
698 }
699 void load_mouse()
700 {
701 PALETTE pal;
702 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
703 if (!cursor_bitmap)
704 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
705
706 enter_sys_pal();
707 MouseSprite::set(-1);
708 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
709 int32_t sz = 16*scale;
710 for(int32_t j = 0; j < 1; ++j)
711 {
712 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
713 if(zcmouse[j])
714 destroy_bitmap(zcmouse[j]);
715 zcmouse[j] = create_bitmap_ex(8,sz,sz);
716 clear_bitmap(zcmouse[j]);
717 clear_bitmap(tmpbmp);
718 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
719 recolor_mouse(tmpbmp);
720 if(sz!=16)
721 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
722 else
723 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
724 destroy_bitmap(tmpbmp);
725 }
726 if(!hw_palette) hw_palette = &RAMpal;
727 zc_set_palette(*hw_palette);
728
729 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
730 clear_bitmap(blankmouse);
731
732 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
733 MouseSprite::assign(ZCM_BLANK, blankmouse);
734 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
735
736 //Reload the mouse
737 if(system_mouse)
738 sys_mouse();
739 else game_mouse();
740
741 destroy_bitmap(blankmouse);
742 destroy_bitmap(cursor_bitmap);
743 exit_sys_pal();
744 }
745
746 // sets the video mode and initializes the palette and mouse sprite
747 117 bool game_vid_mode(int32_t mode,int32_t wait)
748 {
749
1/2
✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
117 if (is_headless())
750 117 return true;
751
752 extern int zq_screen_w, zq_screen_h;
753 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
754 {
755 return false;
756 }
757
758 scrx = (resx-320)>>1;
759 scry = (resy-240)>>1;
760 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
761 zcmouse[q] = NULL;
762 load_mouse();
763
764 for(int32_t i=240; i<256; i++)
765 RAMpal[i]=pal_gui[i];
766
767 zc_set_palette(RAMpal);
768 clear_to_color(screen,BLACK);
769
770 rest(wait);
771 return true;
772 117 }
773
774 8 void null_quest()
775 {
776 char qstdat_string[2048];
777 8 strcpy(qstdat_string, "modules/classic/default.qst");
778
779 #ifdef __EMSCRIPTEN__
780 // The quest template data file is not included because it's really big and isn't really needed
781 // for the player, except to initialize some graphics. Those same graphics exist in this quest file,
782 // which is much smaller.
783 strcpy(qstdat_string, "modules/classic/title_gfx.dat");
784 #endif
785
786 8 byte skip_flags[4] = { 0 };
787
788 8 loadquest(qstdat_string,&QHeader,&QMisc,tunes+ZC_MIDI_COUNT,false,skip_flags,0,false);
789 8 }
790
791 8 void init_NES_mode()
792 {
793 8 null_quest();
794 8 }
795
796 //----------------------------------------------------------------
797
798 qword trianglelines[16]=
799 {
800 0x0000000000000000ULL,
801 0xFD00000000000000ULL,
802 0xFDFD000000000000ULL,
803 0xFDFDFD0000000000ULL,
804 0xFDFDFDFD00000000ULL,
805 0xFDFDFDFDFD000000ULL,
806 0xFDFDFDFDFDFD0000ULL,
807 0xFDFDFDFDFDFDFD00ULL,
808 0xFDFDFDFDFDFDFDFDULL,
809 0x00FDFDFDFDFDFDFDULL,
810 0x0000FDFDFDFDFDFDULL,
811 0x000000FDFDFDFDFDULL,
812 0x00000000FDFDFDFDULL,
813 0x0000000000FDFDFDULL,
814 0x000000000000FDFDULL,
815 0x00000000000000FDULL,
816 };
817
818 word screen_triangles[28][32];
819 /*
820 qword triangles[4][16]= //[direction][value]
821 {
822 {
823 0x00000000, 0x10000000, 0x21000000, 0x32100000, 0x43210000, 0x54321000, 0x65432100, 0x76543210, 0x87654321, 0x88765432, 0x88876543, 0x88887654, 0x88888765, 0x88888876, 0x88888887, 0x88888888
824 },
825 {
826 0x00000000, 0xF0000000, 0xEF000000, 0xFDF00000, 0xCFDF0000, 0xBCFDF000, 0xABCFDF00, 0x9ABCFDF0, 0x89ABCFDF, 0x889ABCFD, 0x8889ABCD, 0x88889ABC, 0x888889AB, 0x8888889A, 0x88888889, 0x88888888
827 },
828 {
829 0x00000000, 0x00000001, 0x00000012, 0x00000123, 0x00001234, 0x00012345, 0x00123456, 0x01234567, 0x12345678, 0x23456788, 0x34567888, 0x45678888, 0x56788888, 0x67888888, 0x78888888, 0x88888888
830 },
831 {
832 0x00000000, 0x0000000F, 0x000000FE, 0x00000FED, 0x0000FEDC, 0x000FEDCB, 0x00FEDCBA, 0x0FEDCBA9, 0xFEDCBA98, 0xEDCBA988, 0xDCBA9888, 0xCBA98888, 0xBA988888, 0xA9888888, 0x98888888, 0x88888888
833 }
834 };
835 */
836
837
838 /*
839 byte triangles[4][16][8]= //[direction][value][line]
840 {
841 {
842 {
843 0, 0, 0, 0, 0, 0, 0, 0
844 },
845 {
846 1, 0, 0, 0, 0, 0, 0, 0
847 },
848 {
849 2, 1, 0, 0, 0, 0, 0, 0
850 },
851 {
852 3, 2, 1, 0, 0, 0, 0, 0
853 },
854 {
855 4, 3, 2, 1, 0, 0, 0, 0
856 },
857 {
858 5, 4, 3, 2, 1, 0, 0, 0
859 },
860 {
861 6, 5, 4, 3, 2, 1, 0, 0
862 },
863 {
864 7, 6, 5, 4, 3, 2, 1, 0
865 },
866 {
867 8, 7, 6, 5, 4, 3, 2, 1
868 },
869 {
870 8, 8, 7, 6, 5, 4, 3, 2
871 },
872 {
873 8, 8, 8, 7, 6, 5, 4, 3
874 },
875 {
876 8, 8, 8, 8, 7, 6, 5, 4
877 },
878 {
879 8, 8, 8, 8, 8, 7, 6, 5
880 },
881 {
882 8, 8, 8, 8, 8, 8, 7, 6
883 },
884 {
885 8, 8, 8, 8, 8, 8, 8, 7
886 },
887 {
888 8, 8, 8, 8, 8, 8, 8, 8
889 }
890 },
891 {
892 {
893 0, 0, 0, 0, 0, 0, 0, 0
894 },
895 {
896 15, 0, 0, 0, 0, 0, 0, 0
897 },
898 {
899 14, 15, 0, 0, 0, 0, 0, 0
900 },
901 {
902 13, 14, 15, 0, 0, 0, 0, 0
903 },
904 {
905 12, 13, 14, 15, 0, 0, 0, 0
906 },
907 {
908 11, 12, 13, 14, 15, 0, 0, 0
909 },
910 {
911 10, 11, 12, 13, 14, 15, 0, 0
912 },
913 {
914 9, 10, 11, 12, 13, 14, 15, 0
915 },
916 {
917 8, 9, 10, 11, 12, 13, 14, 15
918 },
919 {
920 8, 8, 9, 10, 11, 12, 13, 14
921 },
922 {
923 8, 8, 8, 9, 10, 11, 12, 13
924 },
925 {
926 8, 8, 8, 8, 9, 10, 11, 12
927 },
928 {
929 8, 8, 8, 8, 8, 9, 10, 11
930 },
931 {
932 8, 8, 8, 8, 8, 8, 9, 10
933 },
934 {
935 8, 8, 8, 8, 8, 8, 8, 9
936 },
937 {
938 8, 8, 8, 8, 8, 8, 8, 8
939 }
940 },
941 {
942 {
943 0, 0, 0, 0, 0, 0, 0, 0
944 },
945 {
946 0, 0, 0, 0, 0, 0, 0, 1
947 },
948 {
949 0, 0, 0, 0, 0, 0, 1, 2
950 },
951 {
952 0, 0, 0, 0, 0, 1, 2, 3
953 },
954 {
955 0, 0, 0, 0, 1, 2, 3, 4
956 },
957 {
958 0, 0, 0, 1, 2, 3, 4, 5
959 },
960 {
961 0, 0, 1, 2, 3, 4, 5, 6
962 },
963 {
964 0, 1, 2, 3, 4, 5, 6, 7
965 },
966 {
967 1, 2, 3, 4, 5, 6, 7, 8
968 },
969 {
970 2, 3, 4, 5, 6, 7, 8, 8
971 },
972 {
973 3, 4, 5, 6, 7, 8, 8, 8
974 },
975 {
976 4, 5, 6, 7, 8, 8, 8, 8
977 },
978 {
979 5, 6, 7, 8, 8, 8, 8, 8
980 },
981 {
982 6, 7, 8, 8, 8, 8, 8, 8
983 },
984 {
985 7, 8, 8, 8, 8, 8, 8, 8
986 },
987 {
988 8, 8, 8, 8, 8, 8, 8, 8
989 }
990 },
991 {
992 {
993 0, 0, 0, 0, 0, 0, 0, 0
994 },
995 {
996 0, 0, 0, 0, 0, 0, 0, 15
997 },
998 {
999 0, 0, 0, 0, 0, 0, 15, 14
1000 },
1001 {
1002 0, 0, 0, 0, 0, 15, 14, 13
1003 },
1004 {
1005 0, 0, 0, 0, 15, 14, 13, 12
1006 },
1007 {
1008 0, 0, 0, 15, 14, 13, 12, 11
1009 },
1010 {
1011 0, 0, 15, 14, 13, 12, 11, 10
1012 },
1013 {
1014 0, 15, 14, 13, 12, 11, 10, 9
1015 },
1016 {
1017 15, 14, 13, 12, 11, 10, 9, 8
1018 },
1019 {
1020 14, 13, 12, 11, 10, 9, 8, 8
1021 },
1022 {
1023 13, 12, 11, 10, 9, 8, 8, 8
1024 },
1025 {
1026 12, 11, 10, 9, 8, 8, 8, 8
1027 },
1028 {
1029 11, 10, 9, 8, 8, 8, 8, 8
1030 },
1031 {
1032 10, 9, 8, 8, 8, 8, 8, 8
1033 },
1034 {
1035 9, 8, 8, 8, 8, 8, 8, 8
1036 },
1037 {
1038 8, 8, 8, 8, 8, 8, 8, 8
1039 }
1040 }
1041 };
1042 */
1043
1044
1045
1046 /*
1047 for (int32_t blockrow=0; blockrow<30; ++i)
1048 {
1049 for (int32_t linerow=0; linerow<8; ++i)
1050 {
1051 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1052 for (int32_t blockcolumn=0; blockcolumn<40; ++i)
1053 {
1054 triangleline=triangles[0][screen_triangles[blockrow][blockcolumn]][linerow];
1055 ++triangleline;
1056 }
1057 }
1058 }
1059 */
1060
1061 // the ULL suffixes are to prevent this warning:
1062 // warning: integer constant is too large for "int32_t" type
1063
1064 qword triangles[4][16][8]= //[direction][value][line]
1065 {
1066 {
1067 {
1068 0x0000000000000000ULL,
1069 0x0000000000000000ULL,
1070 0x0000000000000000ULL,
1071 0x0000000000000000ULL,
1072 0x0000000000000000ULL,
1073 0x0000000000000000ULL,
1074 0x0000000000000000ULL,
1075 0x0000000000000000ULL
1076 },
1077 {
1078 0xFD00000000000000ULL,
1079 0x0000000000000000ULL,
1080 0x0000000000000000ULL,
1081 0x0000000000000000ULL,
1082 0x0000000000000000ULL,
1083 0x0000000000000000ULL,
1084 0x0000000000000000ULL,
1085 0x0000000000000000ULL
1086 },
1087 {
1088 0xFDFD000000000000ULL,
1089 0xFD00000000000000ULL,
1090 0x0000000000000000ULL,
1091 0x0000000000000000ULL,
1092 0x0000000000000000ULL,
1093 0x0000000000000000ULL,
1094 0x0000000000000000ULL,
1095 0x0000000000000000ULL
1096 },
1097 {
1098 0xFDFDFD0000000000ULL,
1099 0xFDFD000000000000ULL,
1100 0xFD00000000000000ULL,
1101 0x0000000000000000ULL,
1102 0x0000000000000000ULL,
1103 0x0000000000000000ULL,
1104 0x0000000000000000ULL,
1105 0x0000000000000000ULL
1106 },
1107 {
1108 0xFDFDFDFD00000000ULL,
1109 0xFDFDFD0000000000ULL,
1110 0xFDFD000000000000ULL,
1111 0xFD00000000000000ULL,
1112 0x0000000000000000ULL,
1113 0x0000000000000000ULL,
1114 0x0000000000000000ULL,
1115 0x0000000000000000ULL
1116 },
1117 {
1118 0xFDFDFDFDFD000000ULL,
1119 0xFDFDFDFD00000000ULL,
1120 0xFDFDFD0000000000ULL,
1121 0xFDFD000000000000ULL,
1122 0xFD00000000000000ULL,
1123 0x0000000000000000ULL,
1124 0x0000000000000000ULL,
1125 0x0000000000000000ULL
1126 },
1127 {
1128 0xFDFDFDFDFDFD0000ULL,
1129 0xFDFDFDFDFD000000ULL,
1130 0xFDFDFDFD00000000ULL,
1131 0xFDFDFD0000000000ULL,
1132 0xFDFD000000000000ULL,
1133 0xFD00000000000000ULL,
1134 0x0000000000000000ULL,
1135 0x0000000000000000ULL
1136 },
1137 {
1138 0xFDFDFDFDFDFDFD00ULL,
1139 0xFDFDFDFDFDFD0000ULL,
1140 0xFDFDFDFDFD000000ULL,
1141 0xFDFDFDFD00000000ULL,
1142 0xFDFDFD0000000000ULL,
1143 0xFDFD000000000000ULL,
1144 0xFD00000000000000ULL,
1145 0x0000000000000000ULL
1146 },
1147 {
1148 0xFDFDFDFDFDFDFDFDULL,
1149 0xFDFDFDFDFDFDFD00ULL,
1150 0xFDFDFDFDFDFD0000ULL,
1151 0xFDFDFDFDFD000000ULL,
1152 0xFDFDFDFD00000000ULL,
1153 0xFDFDFD0000000000ULL,
1154 0xFDFD000000000000ULL,
1155 0xFD00000000000000ULL
1156 },
1157 {
1158 0xFDFDFDFDFDFDFDFDULL,
1159 0xFDFDFDFDFDFDFDFDULL,
1160 0xFDFDFDFDFDFDFD00ULL,
1161 0xFDFDFDFDFDFD0000ULL,
1162 0xFDFDFDFDFD000000ULL,
1163 0xFDFDFDFD00000000ULL,
1164 0xFDFDFD0000000000ULL,
1165 0xFDFD000000000000ULL
1166 },
1167 {
1168 0xFDFDFDFDFDFDFDFDULL,
1169 0xFDFDFDFDFDFDFDFDULL,
1170 0xFDFDFDFDFDFDFDFDULL,
1171 0xFDFDFDFDFDFDFD00ULL,
1172 0xFDFDFDFDFDFD0000ULL,
1173 0xFDFDFDFDFD000000ULL,
1174 0xFDFDFDFD00000000ULL,
1175 0xFDFDFD0000000000ULL
1176 },
1177 {
1178 0xFDFDFDFDFDFDFDFDULL,
1179 0xFDFDFDFDFDFDFDFDULL,
1180 0xFDFDFDFDFDFDFDFDULL,
1181 0xFDFDFDFDFDFDFDFDULL,
1182 0xFDFDFDFDFDFDFD00ULL,
1183 0xFDFDFDFDFDFD0000ULL,
1184 0xFDFDFDFDFD000000ULL,
1185 0xFDFDFDFD00000000ULL
1186 },
1187 {
1188 0xFDFDFDFDFDFDFDFDULL,
1189 0xFDFDFDFDFDFDFDFDULL,
1190 0xFDFDFDFDFDFDFDFDULL,
1191 0xFDFDFDFDFDFDFDFDULL,
1192 0xFDFDFDFDFDFDFDFDULL,
1193 0xFDFDFDFDFDFDFD00ULL,
1194 0xFDFDFDFDFDFD0000ULL,
1195 0xFDFDFDFDFD000000ULL
1196 },
1197 {
1198 0xFDFDFDFDFDFDFDFDULL,
1199 0xFDFDFDFDFDFDFDFDULL,
1200 0xFDFDFDFDFDFDFDFDULL,
1201 0xFDFDFDFDFDFDFDFDULL,
1202 0xFDFDFDFDFDFDFDFDULL,
1203 0xFDFDFDFDFDFDFDFDULL,
1204 0xFDFDFDFDFDFDFD00ULL,
1205 0xFDFDFDFDFDFD0000ULL
1206 },
1207 {
1208 0xFDFDFDFDFDFDFDFDULL,
1209 0xFDFDFDFDFDFDFDFDULL,
1210 0xFDFDFDFDFDFDFDFDULL,
1211 0xFDFDFDFDFDFDFDFDULL,
1212 0xFDFDFDFDFDFDFDFDULL,
1213 0xFDFDFDFDFDFDFDFDULL,
1214 0xFDFDFDFDFDFDFDFDULL,
1215 0xFDFDFDFDFDFDFD00ULL
1216 },
1217 {
1218 0xFDFDFDFDFDFDFDFDULL,
1219 0xFDFDFDFDFDFDFDFDULL,
1220 0xFDFDFDFDFDFDFDFDULL,
1221 0xFDFDFDFDFDFDFDFDULL,
1222 0xFDFDFDFDFDFDFDFDULL,
1223 0xFDFDFDFDFDFDFDFDULL,
1224 0xFDFDFDFDFDFDFDFDULL,
1225 0xFDFDFDFDFDFDFDFDULL
1226 }
1227 },
1228 {
1229 {
1230 0x0000000000000000ULL,
1231 0x0000000000000000ULL,
1232 0x0000000000000000ULL,
1233 0x0000000000000000ULL,
1234 0x0000000000000000ULL,
1235 0x0000000000000000ULL,
1236 0x0000000000000000ULL,
1237 0x0000000000000000ULL
1238 },
1239 {
1240 0x00000000000000FDULL,
1241 0x0000000000000000ULL,
1242 0x0000000000000000ULL,
1243 0x0000000000000000ULL,
1244 0x0000000000000000ULL,
1245 0x0000000000000000ULL,
1246 0x0000000000000000ULL,
1247 0x0000000000000000ULL
1248 },
1249 {
1250 0x000000000000FDFDULL,
1251 0x00000000000000FDULL,
1252 0x0000000000000000ULL,
1253 0x0000000000000000ULL,
1254 0x0000000000000000ULL,
1255 0x0000000000000000ULL,
1256 0x0000000000000000ULL,
1257 0x0000000000000000ULL
1258 },
1259 {
1260 0x0000000000FDFDFDULL,
1261 0x000000000000FDFDULL,
1262 0x00000000000000FDULL,
1263 0x0000000000000000ULL,
1264 0x0000000000000000ULL,
1265 0x0000000000000000ULL,
1266 0x0000000000000000ULL,
1267 0x0000000000000000ULL
1268 },
1269 {
1270 0x00000000FDFDFDFDULL,
1271 0x0000000000FDFDFDULL,
1272 0x000000000000FDFDULL,
1273 0x00000000000000FDULL,
1274 0x0000000000000000ULL,
1275 0x0000000000000000ULL,
1276 0x0000000000000000ULL,
1277 0x0000000000000000ULL
1278 },
1279 {
1280 0x000000FDFDFDFDFDULL,
1281 0x00000000FDFDFDFDULL,
1282 0x0000000000FDFDFDULL,
1283 0x000000000000FDFDULL,
1284 0x00000000000000FDULL,
1285 0x0000000000000000ULL,
1286 0x0000000000000000ULL,
1287 0x0000000000000000ULL
1288 },
1289 {
1290 0x0000FDFDFDFDFDFDULL,
1291 0x000000FDFDFDFDFDULL,
1292 0x00000000FDFDFDFDULL,
1293 0x0000000000FDFDFDULL,
1294 0x000000000000FDFDULL,
1295 0x00000000000000FDULL,
1296 0x0000000000000000ULL,
1297 0x0000000000000000ULL
1298 },
1299 {
1300 0x00FDFDFDFDFDFDFDULL,
1301 0x0000FDFDFDFDFDFDULL,
1302 0x000000FDFDFDFDFDULL,
1303 0x00000000FDFDFDFDULL,
1304 0x0000000000FDFDFDULL,
1305 0x000000000000FDFDULL,
1306 0x00000000000000FDULL,
1307 0x0000000000000000ULL
1308 },
1309 {
1310 0xFDFDFDFDFDFDFDFDULL,
1311 0x00FDFDFDFDFDFDFDULL,
1312 0x0000FDFDFDFDFDFDULL,
1313 0x000000FDFDFDFDFDULL,
1314 0x00000000FDFDFDFDULL,
1315 0x0000000000FDFDFDULL,
1316 0x000000000000FDFDULL,
1317 0x00000000000000FDULL
1318 },
1319 {
1320 0xFDFDFDFDFDFDFDFDULL,
1321 0xFDFDFDFDFDFDFDFDULL,
1322 0x00FDFDFDFDFDFDFDULL,
1323 0x0000FDFDFDFDFDFDULL,
1324 0x000000FDFDFDFDFDULL,
1325 0x00000000FDFDFDFDULL,
1326 0x0000000000FDFDFDULL,
1327 0x000000000000FDFDULL
1328 },
1329 {
1330 0xFDFDFDFDFDFDFDFDULL,
1331 0xFDFDFDFDFDFDFDFDULL,
1332 0xFDFDFDFDFDFDFDFDULL,
1333 0x00FDFDFDFDFDFDFDULL,
1334 0x0000FDFDFDFDFDFDULL,
1335 0x000000FDFDFDFDFDULL,
1336 0x00000000FDFDFDFDULL,
1337 0x0000000000FDFDFDULL
1338 },
1339 {
1340 0xFDFDFDFDFDFDFDFDULL,
1341 0xFDFDFDFDFDFDFDFDULL,
1342 0xFDFDFDFDFDFDFDFDULL,
1343 0xFDFDFDFDFDFDFDFDULL,
1344 0x00FDFDFDFDFDFDFDULL,
1345 0x0000FDFDFDFDFDFDULL,
1346 0x000000FDFDFDFDFDULL,
1347 0x00000000FDFDFDFDULL
1348 },
1349 {
1350 0xFDFDFDFDFDFDFDFDULL,
1351 0xFDFDFDFDFDFDFDFDULL,
1352 0xFDFDFDFDFDFDFDFDULL,
1353 0xFDFDFDFDFDFDFDFDULL,
1354 0xFDFDFDFDFDFDFDFDULL,
1355 0x00FDFDFDFDFDFDFDULL,
1356 0x0000FDFDFDFDFDFDULL,
1357 0x000000FDFDFDFDFDULL
1358 },
1359 {
1360 0xFDFDFDFDFDFDFDFDULL,
1361 0xFDFDFDFDFDFDFDFDULL,
1362 0xFDFDFDFDFDFDFDFDULL,
1363 0xFDFDFDFDFDFDFDFDULL,
1364 0xFDFDFDFDFDFDFDFDULL,
1365 0xFDFDFDFDFDFDFDFDULL,
1366 0x00FDFDFDFDFDFDFDULL,
1367 0x0000FDFDFDFDFDFDULL
1368 },
1369 {
1370 0xFDFDFDFDFDFDFDFDULL,
1371 0xFDFDFDFDFDFDFDFDULL,
1372 0xFDFDFDFDFDFDFDFDULL,
1373 0xFDFDFDFDFDFDFDFDULL,
1374 0xFDFDFDFDFDFDFDFDULL,
1375 0xFDFDFDFDFDFDFDFDULL,
1376 0xFDFDFDFDFDFDFDFDULL,
1377 0x00FDFDFDFDFDFDFDULL
1378 },
1379 {
1380 0xFDFDFDFDFDFDFDFDULL,
1381 0xFDFDFDFDFDFDFDFDULL,
1382 0xFDFDFDFDFDFDFDFDULL,
1383 0xFDFDFDFDFDFDFDFDULL,
1384 0xFDFDFDFDFDFDFDFDULL,
1385 0xFDFDFDFDFDFDFDFDULL,
1386 0xFDFDFDFDFDFDFDFDULL,
1387 0xFDFDFDFDFDFDFDFDULL
1388 }
1389 },
1390 {
1391 {
1392 0x0000000000000000ULL,
1393 0x0000000000000000ULL,
1394 0x0000000000000000ULL,
1395 0x0000000000000000ULL,
1396 0x0000000000000000ULL,
1397 0x0000000000000000ULL,
1398 0x0000000000000000ULL,
1399 0x0000000000000000ULL
1400 },
1401 {
1402 0x0000000000000000ULL,
1403 0x0000000000000000ULL,
1404 0x0000000000000000ULL,
1405 0x0000000000000000ULL,
1406 0x0000000000000000ULL,
1407 0x0000000000000000ULL,
1408 0x0000000000000000ULL,
1409 0xFD00000000000000ULL
1410 },
1411 {
1412 0x0000000000000000ULL,
1413 0x0000000000000000ULL,
1414 0x0000000000000000ULL,
1415 0x0000000000000000ULL,
1416 0x0000000000000000ULL,
1417 0x0000000000000000ULL,
1418 0xFD00000000000000ULL,
1419 0xFDFD000000000000ULL
1420 },
1421 {
1422 0x0000000000000000ULL,
1423 0x0000000000000000ULL,
1424 0x0000000000000000ULL,
1425 0x0000000000000000ULL,
1426 0x0000000000000000ULL,
1427 0xFD00000000000000ULL,
1428 0xFDFD000000000000ULL,
1429 0xFDFDFD0000000000ULL
1430 },
1431 {
1432 0x0000000000000000ULL,
1433 0x0000000000000000ULL,
1434 0x0000000000000000ULL,
1435 0x0000000000000000ULL,
1436 0xFD00000000000000ULL,
1437 0xFDFD000000000000ULL,
1438 0xFDFDFD0000000000ULL,
1439 0xFDFDFDFD00000000ULL
1440 },
1441 {
1442 0x0000000000000000ULL,
1443 0x0000000000000000ULL,
1444 0x0000000000000000ULL,
1445 0xFD00000000000000ULL,
1446 0xFDFD000000000000ULL,
1447 0xFDFDFD0000000000ULL,
1448 0xFDFDFDFD00000000ULL,
1449 0xFDFDFDFDFD000000ULL
1450 },
1451 {
1452 0x0000000000000000ULL,
1453 0x0000000000000000ULL,
1454 0xFD00000000000000ULL,
1455 0xFDFD000000000000ULL,
1456 0xFDFDFD0000000000ULL,
1457 0xFDFDFDFD00000000ULL,
1458 0xFDFDFDFDFD000000ULL,
1459 0xFDFDFDFDFDFD0000ULL
1460 },
1461 {
1462 0x0000000000000000ULL,
1463 0xFD00000000000000ULL,
1464 0xFDFD000000000000ULL,
1465 0xFDFDFD0000000000ULL,
1466 0xFDFDFDFD00000000ULL,
1467 0xFDFDFDFDFD000000ULL,
1468 0xFDFDFDFDFDFD0000ULL,
1469 0xFDFDFDFDFDFDFD00ULL
1470 },
1471 {
1472 0xFD00000000000000ULL,
1473 0xFDFD000000000000ULL,
1474 0xFDFDFD0000000000ULL,
1475 0xFDFDFDFD00000000ULL,
1476 0xFDFDFDFDFD000000ULL,
1477 0xFDFDFDFDFDFD0000ULL,
1478 0xFDFDFDFDFDFDFD00ULL,
1479 0xFDFDFDFDFDFDFDFDULL
1480 },
1481 {
1482 0xFDFD000000000000ULL,
1483 0xFDFDFD0000000000ULL,
1484 0xFDFDFDFD00000000ULL,
1485 0xFDFDFDFDFD000000ULL,
1486 0xFDFDFDFDFDFD0000ULL,
1487 0xFDFDFDFDFDFDFD00ULL,
1488 0xFDFDFDFDFDFDFDFDULL,
1489 0xFDFDFDFDFDFDFDFDULL
1490 },
1491 {
1492 0xFDFDFD0000000000ULL,
1493 0xFDFDFDFD00000000ULL,
1494 0xFDFDFDFDFD000000ULL,
1495 0xFDFDFDFDFDFD0000ULL,
1496 0xFDFDFDFDFDFDFD00ULL,
1497 0xFDFDFDFDFDFDFDFDULL,
1498 0xFDFDFDFDFDFDFDFDULL,
1499 0xFDFDFDFDFDFDFDFDULL
1500 },
1501 {
1502 0xFDFDFDFD00000000ULL,
1503 0xFDFDFDFDFD000000ULL,
1504 0xFDFDFDFDFDFD0000ULL,
1505 0xFDFDFDFDFDFDFD00ULL,
1506 0xFDFDFDFDFDFDFDFDULL,
1507 0xFDFDFDFDFDFDFDFDULL,
1508 0xFDFDFDFDFDFDFDFDULL,
1509 0xFDFDFDFDFDFDFDFDULL
1510 },
1511 {
1512 0xFDFDFDFDFD000000ULL,
1513 0xFDFDFDFDFDFD0000ULL,
1514 0xFDFDFDFDFDFDFD00ULL,
1515 0xFDFDFDFDFDFDFDFDULL,
1516 0xFDFDFDFDFDFDFDFDULL,
1517 0xFDFDFDFDFDFDFDFDULL,
1518 0xFDFDFDFDFDFDFDFDULL,
1519 0xFDFDFDFDFDFDFDFDULL
1520 },
1521 {
1522 0xFDFDFDFDFDFD0000ULL,
1523 0xFDFDFDFDFDFDFD00ULL,
1524 0xFDFDFDFDFDFDFDFDULL,
1525 0xFDFDFDFDFDFDFDFDULL,
1526 0xFDFDFDFDFDFDFDFDULL,
1527 0xFDFDFDFDFDFDFDFDULL,
1528 0xFDFDFDFDFDFDFDFDULL,
1529 0xFDFDFDFDFDFDFDFDULL
1530 },
1531 {
1532 0xFDFDFDFDFDFDFD00ULL,
1533 0xFDFDFDFDFDFDFDFDULL,
1534 0xFDFDFDFDFDFDFDFDULL,
1535 0xFDFDFDFDFDFDFDFDULL,
1536 0xFDFDFDFDFDFDFDFDULL,
1537 0xFDFDFDFDFDFDFDFDULL,
1538 0xFDFDFDFDFDFDFDFDULL,
1539 0xFDFDFDFDFDFDFDFDULL
1540 },
1541 {
1542 0xFDFDFDFDFDFDFDFDULL,
1543 0xFDFDFDFDFDFDFDFDULL,
1544 0xFDFDFDFDFDFDFDFDULL,
1545 0xFDFDFDFDFDFDFDFDULL,
1546 0xFDFDFDFDFDFDFDFDULL,
1547 0xFDFDFDFDFDFDFDFDULL,
1548 0xFDFDFDFDFDFDFDFDULL,
1549 0xFDFDFDFDFDFDFDFDULL
1550 }
1551 },
1552 {
1553 {
1554 0x0000000000000000ULL,
1555 0x0000000000000000ULL,
1556 0x0000000000000000ULL,
1557 0x0000000000000000ULL,
1558 0x0000000000000000ULL,
1559 0x0000000000000000ULL,
1560 0x0000000000000000ULL,
1561 0x0000000000000000ULL
1562 },
1563 {
1564 0x0000000000000000ULL,
1565 0x0000000000000000ULL,
1566 0x0000000000000000ULL,
1567 0x0000000000000000ULL,
1568 0x0000000000000000ULL,
1569 0x0000000000000000ULL,
1570 0x0000000000000000ULL,
1571 0x00000000000000FDULL
1572 },
1573 {
1574 0x0000000000000000ULL,
1575 0x0000000000000000ULL,
1576 0x0000000000000000ULL,
1577 0x0000000000000000ULL,
1578 0x0000000000000000ULL,
1579 0x0000000000000000ULL,
1580 0x00000000000000FDULL,
1581 0x000000000000FDFDULL
1582 },
1583 {
1584 0x0000000000000000ULL,
1585 0x0000000000000000ULL,
1586 0x0000000000000000ULL,
1587 0x0000000000000000ULL,
1588 0x0000000000000000ULL,
1589 0x00000000000000FDULL,
1590 0x000000000000FDFDULL,
1591 0x0000000000FDFDFDULL
1592 },
1593 {
1594 0x0000000000000000ULL,
1595 0x0000000000000000ULL,
1596 0x0000000000000000ULL,
1597 0x0000000000000000ULL,
1598 0x00000000000000FDULL,
1599 0x000000000000FDFDULL,
1600 0x0000000000FDFDFDULL,
1601 0x00000000FDFDFDFDULL
1602 },
1603 {
1604 0x0000000000000000ULL,
1605 0x0000000000000000ULL,
1606 0x0000000000000000ULL,
1607 0x00000000000000FDULL,
1608 0x000000000000FDFDULL,
1609 0x0000000000FDFDFDULL,
1610 0x00000000FDFDFDFDULL,
1611 0x000000FDFDFDFDFDULL
1612 },
1613 {
1614 0x0000000000000000ULL,
1615 0x0000000000000000ULL,
1616 0x00000000000000FDULL,
1617 0x000000000000FDFDULL,
1618 0x0000000000FDFDFDULL,
1619 0x00000000FDFDFDFDULL,
1620 0x000000FDFDFDFDFDULL,
1621 0x0000FDFDFDFDFDFDULL
1622 },
1623 {
1624 0x0000000000000000ULL,
1625 0x00000000000000FDULL,
1626 0x000000000000FDFDULL,
1627 0x0000000000FDFDFDULL,
1628 0x00000000FDFDFDFDULL,
1629 0x000000FDFDFDFDFDULL,
1630 0x0000FDFDFDFDFDFDULL,
1631 0x00FDFDFDFDFDFDFDULL
1632 },
1633 {
1634 0x00000000000000FDULL,
1635 0x000000000000FDFDULL,
1636 0x0000000000FDFDFDULL,
1637 0x00000000FDFDFDFDULL,
1638 0x000000FDFDFDFDFDULL,
1639 0x0000FDFDFDFDFDFDULL,
1640 0x00FDFDFDFDFDFDFDULL,
1641 0xFDFDFDFDFDFDFDFDULL
1642 },
1643 {
1644 0x000000000000FDFDULL,
1645 0x0000000000FDFDFDULL,
1646 0x00000000FDFDFDFDULL,
1647 0x000000FDFDFDFDFDULL,
1648 0x0000FDFDFDFDFDFDULL,
1649 0x00FDFDFDFDFDFDFDULL,
1650 0xFDFDFDFDFDFDFDFDULL,
1651 0xFDFDFDFDFDFDFDFDULL
1652 },
1653 {
1654 0x0000000000FDFDFDULL,
1655 0x00000000FDFDFDFDULL,
1656 0x000000FDFDFDFDFDULL,
1657 0x0000FDFDFDFDFDFDULL,
1658 0x00FDFDFDFDFDFDFDULL,
1659 0xFDFDFDFDFDFDFDFDULL,
1660 0xFDFDFDFDFDFDFDFDULL,
1661 0xFDFDFDFDFDFDFDFDULL
1662 },
1663 {
1664 0x00000000FDFDFDFDULL,
1665 0x000000FDFDFDFDFDULL,
1666 0x0000FDFDFDFDFDFDULL,
1667 0x00FDFDFDFDFDFDFDULL,
1668 0xFDFDFDFDFDFDFDFDULL,
1669 0xFDFDFDFDFDFDFDFDULL,
1670 0xFDFDFDFDFDFDFDFDULL,
1671 0xFDFDFDFDFDFDFDFDULL
1672 },
1673 {
1674 0x000000FDFDFDFDFDULL,
1675 0x0000FDFDFDFDFDFDULL,
1676 0x00FDFDFDFDFDFDFDULL,
1677 0xFDFDFDFDFDFDFDFDULL,
1678 0xFDFDFDFDFDFDFDFDULL,
1679 0xFDFDFDFDFDFDFDFDULL,
1680 0xFDFDFDFDFDFDFDFDULL,
1681 0xFDFDFDFDFDFDFDFDULL
1682 },
1683 {
1684 0x0000FDFDFDFDFDFDULL,
1685 0x00FDFDFDFDFDFDFDULL,
1686 0xFDFDFDFDFDFDFDFDULL,
1687 0xFDFDFDFDFDFDFDFDULL,
1688 0xFDFDFDFDFDFDFDFDULL,
1689 0xFDFDFDFDFDFDFDFDULL,
1690 0xFDFDFDFDFDFDFDFDULL,
1691 0xFDFDFDFDFDFDFDFDULL
1692 },
1693 {
1694 0x00FDFDFDFDFDFDFDULL,
1695 0xFDFDFDFDFDFDFDFDULL,
1696 0xFDFDFDFDFDFDFDFDULL,
1697 0xFDFDFDFDFDFDFDFDULL,
1698 0xFDFDFDFDFDFDFDFDULL,
1699 0xFDFDFDFDFDFDFDFDULL,
1700 0xFDFDFDFDFDFDFDFDULL,
1701 0xFDFDFDFDFDFDFDFDULL
1702 },
1703 {
1704 0xFDFDFDFDFDFDFDFDULL,
1705 0xFDFDFDFDFDFDFDFDULL,
1706 0xFDFDFDFDFDFDFDFDULL,
1707 0xFDFDFDFDFDFDFDFDULL,
1708 0xFDFDFDFDFDFDFDFDULL,
1709 0xFDFDFDFDFDFDFDFDULL,
1710 0xFDFDFDFDFDFDFDFDULL,
1711 0xFDFDFDFDFDFDFDFDULL
1712 }
1713 }
1714 };
1715
1716 int32_t black_opening_count=0;
1717 int32_t black_opening_x,black_opening_y;
1718 int32_t black_opening_shape;
1719
1720 1508 int32_t choose_opening_shape()
1721 {
1722 // First, count how many bits are set
1723 1508 int32_t numBits=0;
1724 int32_t bitCounter;
1725
1726
2/2
✓ Branch 0 taken 7540 times.
✓ Branch 1 taken 1508 times.
9048 for(int32_t i=0; i<bosMAX; i++)
1727 {
1728
2/2
✓ Branch 0 taken 5816 times.
✓ Branch 1 taken 1724 times.
7540 if(COOLSCROLL&(1<<i))
1729 1724 numBits++;
1730 7540 }
1731
1732 // Shouldn't happen...
1733
1/2
✓ Branch 0 taken 1508 times.
✗ Branch 1 not taken.
1508 if(numBits==0)
1734 return bosCIRCLE;
1735
1736 // Pick a bit
1737 1508 bitCounter=zc_rand()%numBits+1;
1738
1739
2/2
✓ Branch 0 taken 1993 times.
✓ Branch 1 taken 26 times.
2019 for(int32_t i=0; i<bosMAX; i++)
1740 {
1741 // If this bit is set, decrement the bit counter
1742
2/2
✓ Branch 0 taken 355 times.
✓ Branch 1 taken 1638 times.
1993 if(COOLSCROLL&(1<<i))
1743 1638 bitCounter--;
1744
1745 // When the counter hits 0, return a value based on
1746 // which bit it stopped on.
1747 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1748
2/2
✓ Branch 0 taken 1482 times.
✓ Branch 1 taken 511 times.
1993 if(bitCounter==0)
1749 1482 return i;
1750 511 }
1751
1752 // Shouldn't be necessary, but the compiler might complain, at least
1753 26 return bosCIRCLE;
1754 1508 }
1755
1756 396 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1757 {
1758
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 396 times.
396 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1759
1760 396 int32_t w=256, h=224;
1761 396 int32_t blockrows=28, blockcolumns=32;
1762 396 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1763
1764
2/2
✓ Branch 0 taken 11088 times.
✓ Branch 1 taken 396 times.
11484 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1765 {
1766
2/2
✓ Branch 0 taken 354816 times.
✓ Branch 1 taken 11088 times.
365904 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1767 {
1768
2/2
✓ Branch 0 taken 147229 times.
✓ Branch 1 taken 207587 times.
354816 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1769 354816 }
1770 11088 }
1771
1772 396 black_opening_count = 66;
1773 396 black_opening_x = x;
1774 396 black_opening_y = y;
1775 396 lensclk = 0;
1776 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1777
1778
1779
1/2
✓ Branch 0 taken 396 times.
✗ Branch 1 not taken.
396 if(black_opening_shape == bosFADEBLACK)
1780 {
1781 refreshTints();
1782 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1783 }
1784
1/2
✓ Branch 0 taken 396 times.
✗ Branch 1 not taken.
396 if(wait)
1785 {
1786 FFCore.warpScriptCheck();
1787 for(int32_t i=0; i<66; i++)
1788 {
1789 draw_screen(tmpscr);
1790 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
1791 advanceframe(true);
1792
1793 if(Quit)
1794 {
1795 break;
1796 }
1797 }
1798 }
1799 396 }
1800
1801 1112 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1802 {
1803
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1112 times.
1112 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1804
1805 1112 int32_t w=256, h=224;
1806 1112 int32_t blockrows=28, blockcolumns=32;
1807 1112 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1808
1809
2/2
✓ Branch 0 taken 31136 times.
✓ Branch 1 taken 1112 times.
32248 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1810 {
1811
2/2
✓ Branch 0 taken 996352 times.
✓ Branch 1 taken 31136 times.
1027488 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1812 {
1813
2/2
✓ Branch 0 taken 507221 times.
✓ Branch 1 taken 489131 times.
996352 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1814 996352 }
1815 31136 }
1816
1817 1112 black_opening_count = -66;
1818 1112 black_opening_x = x;
1819 1112 black_opening_y = y;
1820 1112 lensclk = 0;
1821
1/2
✓ Branch 0 taken 1112 times.
✗ Branch 1 not taken.
1112 if(black_opening_shape == bosFADEBLACK)
1822 {
1823 refreshTints();
1824 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1825 }
1826
2/2
✓ Branch 0 taken 199 times.
✓ Branch 1 taken 913 times.
1112 if(wait)
1827 {
1828 913 FFCore.warpScriptCheck();
1829
2/2
✓ Branch 0 taken 913 times.
✓ Branch 1 taken 60258 times.
61171 for(int32_t i=0; i<66; i++)
1830 {
1831 60258 draw_screen(tmpscr);
1832 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
1833 60258 advanceframe(true);
1834
1835
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60258 times.
60258 if(Quit)
1836 {
1837 break;
1838 }
1839 60258 }
1840 913 }
1841 1112 }
1842
1843 99528 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1844 {
1845 99528 clear_to_color(tmp_scr,BLACK);
1846 99528 int32_t w=256, h=224;
1847
1848
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 858 times.
✓ Branch 2 taken 660 times.
✓ Branch 3 taken 7656 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 90354 times.
99528 switch(black_opening_shape)
1849 {
1850 case bosOVAL:
1851 {
1852 858 double new_w=(w/2)+abs(w/2-x);
1853 858 double new_h=(h/2)+abs(h/2-y);
1854 858 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1855 858 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1856 858 break;
1857 }
1858
1859 case bosTRIANGLE:
1860 {
1861 660 double new_w=(w/2)+abs(w/2-x);
1862 660 double new_h=(h/2)+abs(h/2-y);
1863 660 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1864 660 double P2= (PI/2);
1865 660 double P23=(2*PI/3);
1866 660 double P43=(4*PI/3);
1867 660 double Pa= (-4*PI*a/(3*max_a));
1868 660 double angle=P2+Pa;
1869 660 double a0=angle;
1870 660 double a2=angle+P23;
1871 660 double a4=angle+P43;
1872 1320 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1873 660 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1874 660 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1875 0);
1876 660 break;
1877 }
1878
1879 case bosSMAS:
1880 {
1881
2/2
✓ Branch 0 taken 4158 times.
✓ Branch 1 taken 3498 times.
7656 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1882
1883
2/2
✓ Branch 0 taken 214368 times.
✓ Branch 1 taken 7656 times.
222024 for(int32_t blockrow=0; blockrow<28; ++blockrow) //30
1884 {
1885
2/2
✓ Branch 0 taken 1714944 times.
✓ Branch 1 taken 214368 times.
1929312 for(int32_t linerow=0; linerow<8; ++linerow)
1886 {
1887 1714944 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1888
1889
2/2
✓ Branch 0 taken 54878208 times.
✓ Branch 1 taken 1714944 times.
56593152 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1890 {
1891 164634624 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1892
6/6
✓ Branch 0 taken 39546648 times.
✓ Branch 1 taken 15331560 times.
✓ Branch 2 taken 35934032 times.
✓ Branch 3 taken 18944176 times.
✓ Branch 4 taken 20602472 times.
✓ Branch 5 taken 15331560 times.
54878208 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1893 54878208 [linerow];
1894 54878208 ++triangleline;
1895
1896
2/2
✓ Branch 0 taken 48018432 times.
✓ Branch 1 taken 6859776 times.
54878208 if(linerow==0)
1897 {
1898 6859776 }
1899 54878208 }
1900 1714944 }
1901 214368 }
1902
1903 7656 break;
1904 }
1905
1906 case bosFADEBLACK:
1907 {
1908 if(black_opening_count<0)
1909 {
1910 black_fade(zc_min(-black_opening_count,63));
1911 }
1912 else if(black_opening_count>0)
1913 {
1914 black_fade(63-zc_max(black_opening_count-3,0));
1915 }
1916 else black_fade(0);
1917 return; //no blitting from tmp_scr!
1918 }
1919
1920 90354 case bosCIRCLE:
1921 default:
1922 {
1923 90354 double new_w=(w/2)+abs(w/2-x);
1924 90354 double new_h=(h/2)+abs(h/2-y);
1925 90354 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1926 //circlefill(tmp_scr,x,y,a<<3,0);
1927 90354 circlefill(tmp_scr,x,y,r,0);
1928 90354 break;
1929 }
1930 }
1931
1932 99528 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1933 99528 }
1934
1935
1936 void black_fade(int32_t fadeamnt)
1937 {
1938 for(int32_t i=0; i < 0xEF; i++)
1939 {
1940 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,63);
1941 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,63);
1942 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,63);
1943 }
1944
1945 refreshpal = true;
1946 }
1947
1948 //----------------------------------------------------------------
1949
1950 38831728 bool item_disabled(int32_t item) //is this item disabled?
1951 {
1952
2/2
✓ Branch 0 taken 1832457 times.
✓ Branch 1 taken 36999271 times.
38831728 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1953 }
1954
1955 7618361 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1956 {
1957
2/2
✓ Branch 0 taken 135248 times.
✓ Branch 1 taken 7483113 times.
7618361 if(current_item(item_type, true) >=item)
1958 {
1959 135248 return true;
1960 }
1961
1962 7483113 return false;
1963 7618361 }
1964
1965 25026143 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1966 {
1967
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 26467 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3220277 times.
✓ Branch 6 taken 16170214 times.
✓ Branch 7 taken 5493498 times.
✓ Branch 8 taken 115687 times.
25026143 switch(item_type)
1968 {
1969 case itype_bomb:
1970 case itype_sbomb:
1971 {
1972 int32_t itemid = getItemID(itemsbuf, item_type, it);
1973
1974 if(itemid == -1)
1975 return false;
1976
1977 return (game->get_item(itemid));
1978 }
1979
1980 case itype_clock:
1981 {
1982 26467 int32_t itemid = getItemID(itemsbuf, item_type, it);
1983
1984
2/4
✓ Branch 0 taken 26467 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26467 times.
✗ Branch 3 not taken.
26467 if(itemid != -1 && (itemsbuf[itemid].flags & ITEM_FLAG1)) //Active clock
1985 return (game->get_item(itemid));
1986 26467 return Hero.getClock()?1:0;
1987 }
1988
1989 case itype_key:
1990 return (game->get_keys()>0);
1991
1992 case itype_magiccontainer:
1993 return (game->get_maxmagic()>=game->get_mp_per_block());
1994
1995 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1996 {
1997
2/3
✓ Branch 0 taken 280536 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2939741 times.
3220277 switch(it)
1998 {
1999 case -2:
2000 {
2001 for(int32_t i=0; i<MAXLEVELS; i++)
2002 {
2003 if(game->lvlitems[i]&liTRIFORCE)
2004 {
2005 return true;
2006 }
2007 }
2008
2009 return false;
2010 }
2011
2012 case -1:
2013 2939741 return (game->lvlitems[dlevel]&liTRIFORCE);
2014
2015 default:
2016
2/4
✓ Branch 0 taken 280536 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 280536 times.
280536 if(it>=0&&it<MAXLEVELS)
2017 {
2018 280536 return (game->lvlitems[it]&liTRIFORCE);
2019 }
2020
2021 break;
2022 }
2023
2024 return 0;
2025 }
2026
2027 case itype_map: //it: -2=any, -1=current level, other=that level
2028 {
2029
2/3
✓ Branch 0 taken 402420 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15767794 times.
16170214 switch(it)
2030 {
2031 case -2:
2032 {
2033 for(int32_t i=0; i<MAXLEVELS; i++)
2034 {
2035 if(game->lvlitems[i]&liMAP)
2036 {
2037 return true;
2038 }
2039 }
2040
2041 return false;
2042 }
2043
2044 case -1:
2045 15767794 return (game->lvlitems[dlevel]&liMAP)!=0;
2046
2047 default:
2048
2/4
✓ Branch 0 taken 402420 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 402420 times.
402420 if(it>=0&&it<MAXLEVELS)
2049 {
2050 402420 return (game->lvlitems[it]&liMAP)!=0;
2051 }
2052
2053 break;
2054 }
2055
2056 return 0;
2057 }
2058
2059 case itype_compass: //it: -2=any, -1=current level, other=that level
2060 {
2061
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 5493498 times.
5493498 switch(it)
2062 {
2063 case -2:
2064 {
2065 for(int32_t i=0; i<MAXLEVELS; i++)
2066 {
2067 if(game->lvlitems[i]&liCOMPASS)
2068 {
2069 return true;
2070 }
2071 }
2072
2073 return false;
2074 }
2075
2076 case -1:
2077 5493498 return (game->lvlitems[dlevel]&liCOMPASS)!=0;
2078
2079 default:
2080 if(it>=0&&it<MAXLEVELS)
2081 {
2082 return (game->lvlitems[it]&liCOMPASS)!=0;
2083 }
2084
2085 break;
2086 }
2087 return 0;
2088 }
2089
2090 case itype_bosskey: //it: -2=any, -1=current level, other=that level
2091 {
2092
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 115687 times.
115687 switch(it)
2093 {
2094 case -2:
2095 {
2096 for(int32_t i=0; i<MAXLEVELS; i++)
2097 {
2098 if(game->lvlitems[i]&liBOSSKEY)
2099 {
2100 return true;
2101 }
2102 }
2103
2104 return false;
2105 }
2106
2107 case -1:
2108 115687 return (game->lvlitems[dlevel]&liBOSSKEY)?1:0;
2109
2110 default:
2111 if(it>=0&&it<MAXLEVELS)
2112 {
2113 return (game->lvlitems[it]&liBOSSKEY)?1:0;
2114 }
2115 break;
2116 }
2117 return 0;
2118 }
2119
2120 default:
2121 //it=(1<<(it-1));
2122 /*if (item_type>=itype_max)
2123 {
2124 enter_sys_pal();
2125 jwin_alert("Error","has_item exception",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2126 exit_sys_pal();
2127
2128 return false;
2129 }*/
2130 int32_t itemid = getItemID(itemsbuf, item_type, it);
2131
2132 if(itemid == -1)
2133 return false;
2134
2135 return game->get_item(itemid);
2136 }
2137 25026143 }
2138
2139
2140 51803521 int32_t current_item(int32_t item_type, bool checkenabled) //item currently being used
2141 {
2142
9/9
✓ Branch 0 taken 26467 times.
✓ Branch 1 taken 51591785 times.
✓ Branch 2 taken 26467 times.
✓ Branch 3 taken 26467 times.
✓ Branch 4 taken 26467 times.
✓ Branch 5 taken 26467 times.
✓ Branch 6 taken 26467 times.
✓ Branch 7 taken 26467 times.
✓ Branch 8 taken 26467 times.
51803521 switch(item_type)
2143 {
2144 case itype_clock:
2145 {
2146 26467 int32_t maxid = getHighestLevelOfFamily(game, itemsbuf, item_type, checkenabled);
2147
2148
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 26467 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
26467 if(maxid != -1 && (itemsbuf[maxid].flags & ITEM_FLAG1)) //Active clock
2149 return itemsbuf[maxid].fam_type;
2150
2151 26467 return has_item(itype_clock,1) ? 1 : 0;
2152 }
2153
2154 case itype_key:
2155 26467 return game->get_keys();
2156
2157 case itype_lkey:
2158 26467 return game->lvlkeys[get_dlevel()];
2159
2160 case itype_magiccontainer:
2161 26467 return game->get_maxmagic()/game->get_mp_per_block();
2162
2163 case itype_triforcepiece:
2164 {
2165 26467 int32_t count=0;
2166
2167
2/2
✓ Branch 0 taken 13551104 times.
✓ Branch 1 taken 26467 times.
13577571 for(int32_t i=0; i<MAXLEVELS; i++)
2168 {
2169 13551104 count+=(game->lvlitems[i]&liTRIFORCE)?1:0;
2170 13551104 }
2171
2172 26467 return count;
2173 }
2174
2175 case itype_map:
2176 {
2177 26467 int32_t count=0;
2178
2179
2/2
✓ Branch 0 taken 13551104 times.
✓ Branch 1 taken 26467 times.
13577571 for(int32_t i=0; i<MAXLEVELS; i++)
2180 {
2181 13551104 count+=(game->lvlitems[i]&liMAP)?1:0;
2182 13551104 }
2183
2184 26467 return count;
2185 }
2186
2187 case itype_compass:
2188 {
2189 26467 int32_t count=0;
2190
2191
2/2
✓ Branch 0 taken 13551104 times.
✓ Branch 1 taken 26467 times.
13577571 for(int32_t i=0; i<MAXLEVELS; i++)
2192 {
2193 13551104 count+=(game->lvlitems[i]&liCOMPASS)?1:0;
2194 13551104 }
2195
2196 26467 return count;
2197 }
2198
2199 case itype_bosskey:
2200 {
2201 26467 int32_t count=0;
2202
2203
2/2
✓ Branch 0 taken 13551104 times.
✓ Branch 1 taken 26467 times.
13577571 for(int32_t i=0; i<MAXLEVELS; i++)
2204 {
2205 13551104 count+=(game->lvlitems[i]&liBOSSKEY)?1:0;
2206 13551104 }
2207
2208 26467 return count;
2209 }
2210
2211 default:
2212 51591785 int32_t maxid = getHighestLevelOfFamily(game, itemsbuf, item_type, checkenabled);
2213
2214
2/2
✓ Branch 0 taken 9875888 times.
✓ Branch 1 taken 41715897 times.
51591785 if(maxid == -1)
2215 41715897 return 0;
2216
2217 9875888 return itemsbuf[maxid].fam_type;
2218 }
2219 51803521 }
2220
2221 44185160 int32_t current_item(int32_t item_type) //item currently being used
2222 {
2223 44185160 return current_item(item_type, true);
2224 }
2225
2226 117 std::map<int32_t, int32_t> itemcache;
2227 117 std::map<int32_t, int32_t> itemcache_cost;
2228
2229 void removeFromItemCache(int32_t itemclass)
2230 {
2231 itemcache.erase(itemclass);
2232 itemcache_cost.erase(itemclass);
2233 cache_tile_mod_clear();
2234 }
2235
2236 5861589 void flushItemCache(bool justcost)
2237 {
2238 5861589 itemcache_cost.clear();
2239
2/2
✓ Branch 0 taken 5831552 times.
✓ Branch 1 taken 30037 times.
5861589 if(!justcost)
2240 30037 itemcache.clear();
2241
2/2
✓ Branch 0 taken 5831120 times.
✓ Branch 1 taken 432 times.
5831552 else if(replay_version_check(0,19))
2242 5831120 return;
2243
2244 30469 cache_tile_mod_clear();
2245
2246 //also fix the active subscreen if items were deleted -DD
2247
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30469 times.
30469 if(game != NULL)
2248 {
2249 30469 verifyBothWeapons();
2250 30469 refresh_subscr_items();
2251 30469 }
2252 5861589 }
2253
2254 // This is used often, so it should be as direct as possible.
2255 237714092 int32_t _c_item_id_internal(int32_t itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2256 {
2257 237714092 bool use_cost_cache = replay_version_check(19);
2258
2/2
✓ Branch 0 taken 196304690 times.
✓ Branch 1 taken 41409402 times.
237714092 if(jinx_check)
2259 {
2260
4/4
✓ Branch 0 taken 39648378 times.
✓ Branch 1 taken 1761024 times.
✓ Branch 2 taken 566304 times.
✓ Branch 3 taken 39082074 times.
41409402 if(!(HeroSwordClk() || HeroItemClk()))
2261 39082074 jinx_check = false; //not jinxed
2262 41409402 }
2263
2/2
✓ Branch 0 taken 113585 times.
✓ Branch 1 taken 237600507 times.
237714092 if(!Hero.BunnyClock())
2264 237600507 check_bunny = false; //not bunnied
2265
2/2
✓ Branch 0 taken 214190172 times.
✓ Branch 1 taken 23523920 times.
237714092 if(itemtype == itype_ring) checkmagic = true;
2266
4/4
✓ Branch 0 taken 235386764 times.
✓ Branch 1 taken 2327328 times.
✓ Branch 2 taken 211849481 times.
✓ Branch 3 taken 23242659 times.
472806232 if (!jinx_check && !check_bunny
2267
3/4
✓ Branch 0 taken 235386764 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 235092140 times.
✓ Branch 3 taken 294624 times.
235386764 && (use_cost_cache || itemtype != itype_ring))
2268 {
2269
4/4
✓ Branch 0 taken 171793023 times.
✓ Branch 1 taken 40351082 times.
✓ Branch 2 taken 171631357 times.
✓ Branch 3 taken 161666 times.
212144105 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2270 212144105 auto res = cache.find(itemtype);
2271
2272
2/2
✓ Branch 0 taken 196815949 times.
✓ Branch 1 taken 15328156 times.
212144105 if(res != cache.end())
2273 196815949 return res->second;
2274 15328156 }
2275
2276 40898143 int32_t result = -1;
2277 40898143 int32_t highestlevel = -1;
2278
2279
2/2
✓ Branch 0 taken 10469924608 times.
✓ Branch 1 taken 40898143 times.
10510822751 for(int32_t i=0; i<MAXITEMS; i++)
2280 {
2281
5/6
✓ Branch 0 taken 740217966 times.
✓ Branch 1 taken 9729706642 times.
✓ Branch 2 taken 16232093 times.
✓ Branch 3 taken 723985873 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 16232093 times.
10469924608 if(game->get_item(i) && itemsbuf[i].family==itemtype && !item_disabled(i))
2282 {
2283
4/4
✓ Branch 0 taken 15725229 times.
✓ Branch 1 taken 506864 times.
✓ Branch 2 taken 8694 times.
✓ Branch 3 taken 15716535 times.
16232093 if(checkmagic && itemtype != itype_magicring)
2284
2/2
✓ Branch 0 taken 15716377 times.
✓ Branch 1 taken 158 times.
15716535 if(!checkmagiccost(i))
2285 158 continue;
2286
6/6
✓ Branch 0 taken 14671645 times.
✓ Branch 1 taken 1560290 times.
✓ Branch 2 taken 106359 times.
✓ Branch 3 taken 1453931 times.
✓ Branch 4 taken 863949 times.
✓ Branch 5 taken 696341 times.
16231935 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2287
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 696341 times.
696341 if(!(itemsbuf[i].flags & ITEM_JINX_IMMUNE))
2288 696341 continue;
2289
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 15535594 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15535594 if(check_bunny && !checkbunny(i))
2290 continue;
2291
2292
2/2
✓ Branch 0 taken 153893 times.
✓ Branch 1 taken 15381701 times.
15535594 if(itemsbuf[i].fam_type >= highestlevel)
2293 {
2294 15381701 highestlevel = itemsbuf[i].fam_type;
2295 15381701 result=i;
2296 15381701 }
2297 15535594 }
2298 10469228109 }
2299
2300
3/4
✓ Branch 0 taken 38570815 times.
✓ Branch 1 taken 2327328 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 38570815 times.
40898143 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2301 {
2302
2/2
✓ Branch 0 taken 4460 times.
✓ Branch 1 taken 38566355 times.
38570815 if (use_cost_cache)
2303 {
2304
2/2
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 2192 times.
4460 if (!checkmagic)
2305 2192 itemcache[itemtype] = result;
2306
5/6
✓ Branch 0 taken 2192 times.
✓ Branch 1 taken 2268 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 2188 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4460 if (checkmagic || result < 0 || checkmagiccost(result))
2307 4460 itemcache_cost[itemtype] = result;
2308 4460 }
2309 else
2310 {
2311 38566355 itemcache[itemtype] = result;
2312 }
2313 38570815 }
2314 40898143 return result;
2315 237714092 }
2316
2317 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2318 235830977 int32_t current_item_id(int32_t itype, bool checkmagic, bool jinx_check, bool check_bunny)
2319 {
2320
2/4
✓ Branch 0 taken 235830977 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 235830977 times.
235830977 if(itype < 0 || itype >= itype_max) return -1;
2321
1/2
✓ Branch 0 taken 235830977 times.
✗ Branch 1 not taken.
235830977 if(game->OverrideItems[itype] > -2)
2322 {
2323 auto ovid = game->OverrideItems[itype];
2324 if(ovid < 0 || ovid >= MAXITEMS)
2325 return -1;
2326 if(itemsbuf[ovid].family == itype)
2327 {
2328 if(itype == itype_magicring)
2329 checkmagic = false;
2330 else if(itype == itype_ring)
2331 checkmagic = true;
2332
2333 if(checkmagic && !checkmagiccost(ovid))
2334 return -1;
2335 if(jinx_check && !(itemsbuf[ovid].flags & ITEM_JINX_IMMUNE)
2336 && (usesSwordJinx(ovid) ? HeroSwordClk() : HeroItemClk()))
2337 return -1;
2338 return ovid;
2339 }
2340 }
2341 235830977 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2342
2/2
✓ Branch 0 taken 39526287 times.
✓ Branch 1 taken 196304690 times.
235830977 if(!jinx_check) //If not already a jinx-immune-only check...
2343 {
2344 //And the player IS jinxed...
2345
4/4
✓ Branch 0 taken 194886643 times.
✓ Branch 1 taken 1418047 times.
✓ Branch 2 taken 465068 times.
✓ Branch 3 taken 194421575 times.
196304690 if(HeroSwordClk() || HeroItemClk())
2346 {
2347 //Then do a jinx-immune-only check here
2348 1883115 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2349 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2350 //Should NOT need a compat rule, as this should always return -1 in old quests.
2351
2/2
✓ Branch 0 taken 523197 times.
✓ Branch 1 taken 1359918 times.
1883115 if(ret2 > -1) return ret2;
2352 1359918 }
2353 195781493 }
2354 235307780 return ret;
2355 235830977 }
2356
2357 19471445 int32_t current_item_power(int32_t itemtype)
2358 {
2359 19471445 int32_t result = current_item_id(itemtype,true);
2360
2/2
✓ Branch 0 taken 14106681 times.
✓ Branch 1 taken 5364764 times.
19471445 return (result<0) ? 0 : itemsbuf[result].power;
2361 }
2362
2363 11 int32_t heart_container_id()
2364 {
2365
1/2
✓ Branch 0 taken 319 times.
✗ Branch 1 not taken.
319 for(int32_t i=0; i<MAXITEMS; i++)
2366 {
2367
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 308 times.
319 if(itemsbuf[i].family == itype_heartcontainer)
2368 {
2369 11 return i;
2370 }
2371 308 }
2372 return -1;
2373 11 }
2374
2375 struct tilemod_cache_state_t
2376 {
2377
6/6
✓ Branch 0 taken 26147 times.
✓ Branch 1 taken 6027753 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 6027751 times.
✓ Branch 4 taken 318 times.
✓ Branch 5 taken 6027433 times.
12081653 bool operator==(const tilemod_cache_state_t&) const = default;
2378
2379 bool valid;
2380 bool bunny_clock;
2381 bool superman;
2382 int shield;
2383 };
2384 tilemod_cache_state_t tilemod_cache_state;
2385 int32_t tilemod_cache_value;
2386
2387 31001 void cache_tile_mod_clear()
2388 {
2389 31001 tilemod_cache_state = {false};
2390 31001 }
2391
2392 6053900 int32_t item_tile_mod()
2393 {
2394 24215600 tilemod_cache_state_t state = {
2395 .valid = true,
2396 6053900 .bunny_clock = Hero.BunnyClock() != 0,
2397 6053900 .superman = Hero.superman,
2398 6053900 .shield = Hero.active_shield_id,
2399 };
2400
2/2
✓ Branch 0 taken 6027433 times.
✓ Branch 1 taken 26467 times.
6053900 if (tilemod_cache_state == state)
2401 6027433 return tilemod_cache_value;
2402
2403 26467 int32_t tile=0;
2404 26467 bool check_bombcost = !get_qr(qr_BROKEN_BOMB_AMMO_COSTS);
2405
3/4
✓ Branch 0 taken 26467 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21489 times.
✓ Branch 3 taken 4978 times.
26467 if(check_bombcost || game->get_bombs())
2406 {
2407 21489 int32_t itemid = current_item_id(itype_bomb,check_bombcost);
2408
3/4
✓ Branch 0 taken 20340 times.
✓ Branch 1 taken 1149 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 20340 times.
21489 if(itemid > -1 && checkbunny(itemid))
2409 20340 tile+=itemsbuf[itemid].ltm;
2410 21489 }
2411
2412
3/4
✓ Branch 0 taken 26467 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6765 times.
✓ Branch 3 taken 19702 times.
26467 if(check_bombcost || game->get_sbombs())
2413 {
2414 6765 int32_t itemid = current_item_id(itype_sbomb,check_bombcost);
2415
3/4
✓ Branch 0 taken 6759 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6759 times.
6765 if(itemid > -1 && checkbunny(itemid))
2416 6759 tile+=itemsbuf[itemid].ltm;
2417 6765 }
2418
2419
2/2
✓ Branch 0 taken 25610 times.
✓ Branch 1 taken 857 times.
26467 if(current_item(itype_clock))
2420 {
2421 857 int32_t itemid =
2422
1/2
✓ Branch 0 taken 857 times.
✗ Branch 1 not taken.
857 get_qr(qr_HARDCODED_LITEM_LTMS)
2423 ? iClock
2424 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2425
2/4
✓ Branch 0 taken 857 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 857 times.
857 if(itemid > -1 && checkbunny(itemid))
2426 857 tile+=itemsbuf[itemid].ltm;
2427 857 }
2428
2429
2/2
✓ Branch 0 taken 20192 times.
✓ Branch 1 taken 6275 times.
26467 if(current_item(itype_key))
2430 {
2431 6275 int32_t itemid =
2432
1/2
✓ Branch 0 taken 6275 times.
✗ Branch 1 not taken.
6275 get_qr(qr_HARDCODED_LITEM_LTMS)
2433 ? iKey
2434 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2435
2/4
✓ Branch 0 taken 6275 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6275 times.
6275 if(itemid > -1 && checkbunny(itemid))
2436 6275 tile+=itemsbuf[itemid].ltm;
2437 6275 }
2438
2439
2/2
✓ Branch 0 taken 24989 times.
✓ Branch 1 taken 1478 times.
26467 if(current_item(itype_lkey))
2440 {
2441 1478 int32_t itemid =
2442
2/2
✓ Branch 0 taken 1472 times.
✓ Branch 1 taken 6 times.
1478 get_qr(qr_HARDCODED_LITEM_LTMS)
2443 ? iLevelKey
2444 6 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2445
2/4
✓ Branch 0 taken 1478 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1478 times.
1478 if(itemid > -1 && checkbunny(itemid))
2446 1478 tile+=itemsbuf[itemid].ltm;
2447 1478 }
2448
2449
2/2
✓ Branch 0 taken 5912 times.
✓ Branch 1 taken 20555 times.
26467 if(current_item(itype_map))
2450 {
2451 20555 int32_t itemid =
2452
2/2
✓ Branch 0 taken 20553 times.
✓ Branch 1 taken 2 times.
20555 get_qr(qr_HARDCODED_LITEM_LTMS)
2453 ? iMap
2454 2 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2455
2/4
✓ Branch 0 taken 20555 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20555 times.
20555 if(itemid > -1 && checkbunny(itemid))
2456 20555 tile+=itemsbuf[itemid].ltm;
2457 20555 }
2458
2459
2/2
✓ Branch 0 taken 5698 times.
✓ Branch 1 taken 20769 times.
26467 if(current_item(itype_compass))
2460 {
2461 20769 int32_t itemid =
2462
2/2
✓ Branch 0 taken 20368 times.
✓ Branch 1 taken 401 times.
20769 get_qr(qr_HARDCODED_LITEM_LTMS)
2463 ? iCompass
2464 401 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2465
2/4
✓ Branch 0 taken 20769 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20769 times.
20769 if(itemid > -1 && checkbunny(itemid))
2466 20769 tile+=itemsbuf[itemid].ltm;
2467 20769 }
2468
2469
2/2
✓ Branch 0 taken 15499 times.
✓ Branch 1 taken 10968 times.
26467 if(current_item(itype_bosskey))
2470 {
2471 10968 int32_t itemid =
2472
1/2
✓ Branch 0 taken 10968 times.
✗ Branch 1 not taken.
10968 get_qr(qr_HARDCODED_LITEM_LTMS)
2473 ? iBossKey
2474 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2475
2/4
✓ Branch 0 taken 10968 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10968 times.
10968 if(itemid > -1 && checkbunny(itemid))
2476 10968 tile+=itemsbuf[itemid].ltm;
2477 10968 }
2478
2479
2/2
✓ Branch 0 taken 13012 times.
✓ Branch 1 taken 13455 times.
26467 if(current_item(itype_magiccontainer))
2480 {
2481 13455 int32_t itemid =
2482
2/2
✓ Branch 0 taken 13001 times.
✓ Branch 1 taken 454 times.
13455 get_qr(qr_HARDCODED_LITEM_LTMS)
2483 ? iMagicC
2484 454 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2485
3/4
✓ Branch 0 taken 13455 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 13438 times.
13455 if(itemid > -1 && checkbunny(itemid))
2486 13438 tile+=itemsbuf[itemid].ltm;
2487 13455 }
2488
2489
2/2
✓ Branch 0 taken 7161 times.
✓ Branch 1 taken 19306 times.
26467 if(current_item(itype_triforcepiece))
2490 {
2491 19306 int32_t itemid =
2492
1/2
✓ Branch 0 taken 19306 times.
✗ Branch 1 not taken.
19306 get_qr(qr_HARDCODED_LITEM_LTMS)
2493 ? iTriforce
2494 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2495
2/4
✓ Branch 0 taken 19306 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19306 times.
19306 if(itemid > -1 && checkbunny(itemid))
2496 19306 tile+=itemsbuf[itemid].ltm;
2497 19306 }
2498
2499
2/2
✓ Branch 0 taken 13551104 times.
✓ Branch 1 taken 26467 times.
13577571 for(int32_t i=0; i<itype_max; i++)
2500 {
2501
2/2
✓ Branch 0 taken 13294592 times.
✓ Branch 1 taken 256512 times.
13551104 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2502 {
2503
2/2
✓ Branch 0 taken 5010 times.
✓ Branch 1 taken 251502 times.
256512 switch(i)
2504 {
2505 case itype_bomb:
2506 case itype_sbomb:
2507 case itype_clock:
2508 case itype_key:
2509 case itype_lkey:
2510 case itype_map:
2511 case itype_compass:
2512 case itype_bosskey:
2513 case itype_magiccontainer:
2514 case itype_triforcepiece:
2515 5010 continue; //already handled
2516 }
2517 251502 }
2518 13546094 int32_t itemid = current_item_id(i,false);
2519
2/2
✓ Branch 0 taken 13519627 times.
✓ Branch 1 taken 26467 times.
13546094 if(i == itype_shield)
2520 26467 itemid = getCurrentShield(false);
2521
2522
4/4
✓ Branch 0 taken 353604 times.
✓ Branch 1 taken 13192490 times.
✓ Branch 2 taken 919 times.
✓ Branch 3 taken 352685 times.
13546094 if(itemid < 0 || !checkbunny(itemid))
2523 13193409 continue;
2524
2525 352685 itemdata const& itm = itemsbuf[itemid];
2526
2527
2/2
✓ Branch 0 taken 328767 times.
✓ Branch 1 taken 23918 times.
352685 switch(itm.family)
2528 {
2529 case itype_shield:
2530
1/2
✓ Branch 0 taken 23918 times.
✗ Branch 1 not taken.
23918 if(itm.flags & ITEM_FLAG9) //active shield
2531 {
2532 if(!usingActiveShield(itemid))
2533 {
2534 tile+=itm.misc6; //'Inactive PTM'
2535 continue;
2536 }
2537 }
2538 23918 break;
2539 }
2540
2541 352685 tile+=itm.ltm;
2542 352685 }
2543
2544 26467 tilemod_cache_value = tile;
2545 26467 tilemod_cache_state = state;
2546 26467 return tile;
2547 6053900 }
2548
2549 6053900 int32_t bunny_tile_mod()
2550 {
2551
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 6052030 times.
6053900 if(Hero.BunnyClock())
2552 {
2553 1870 return game->get_bunny_ltm();
2554 }
2555 6052030 return 0;
2556 6053900 }
2557
2558 // Hints are drawn on a separate layer to combo reveals.
2559 16332 void draw_lens_under(BITMAP *dest, bool layer)
2560 {
2561 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2562 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2563 //Lens flag 3: Don't show armos/chest/dive items
2564 //Lens flag 4: Show Raft Paths
2565 //Lens flag 5: Show Invisible Enemies
2566
4/4
✓ Branch 0 taken 456 times.
✓ Branch 1 taken 15876 times.
✓ Branch 2 taken 7938 times.
✓ Branch 3 taken 7938 times.
16332 bool hints = (itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG1));
2567
2568 16332 int32_t strike_hint_table[11]=
2569 {
2570 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2571 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2572 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2573 };
2574
2575 // int32_t page = tmpscr->cpage;
2576 {
2577 16332 int32_t blink_rate=flash_reduction_enabled()?6:1;
2578 // int32_t temptimer=0;
2579 16332 int32_t tempitem, tempweapon=0;
2580 16332 strike_hint=strike_hint_table[strike_hint_counter];
2581
2582
2/2
✓ Branch 0 taken 15842 times.
✓ Branch 1 taken 490 times.
16332 if(strike_hint_timer>32)
2583 {
2584 490 strike_hint_timer=0;
2585 490 strike_hint_counter=((strike_hint_counter+1)%11);
2586 490 }
2587
2588 16332 ++strike_hint_timer;
2589
2590
2/2
✓ Branch 0 taken 2874432 times.
✓ Branch 1 taken 16332 times.
2890764 for(int32_t i=0; i<176; i++)
2591 {
2592 2874432 int32_t x = (i & 15) << 4;
2593 2874432 int32_t y = (i & 0xF0) + playing_field_offset;
2594 2874432 int32_t tempitemx=-16, tempitemy=-16;
2595 2874432 int32_t tempweaponx=-16, tempweapony=-16;
2596
2597
2/2
✓ Branch 0 taken 5748864 times.
✓ Branch 1 taken 2874432 times.
8623296 for(int32_t iter=0; iter<2; ++iter)
2598 {
2599 5748864 int32_t checkflag=0;
2600
2601
2/2
✓ Branch 0 taken 2874432 times.
✓ Branch 1 taken 2874432 times.
5748864 if(iter==0)
2602 {
2603 2874432 checkflag=combobuf[tmpscr->data[i]].flag;
2604 2874432 }
2605 else
2606 {
2607 2874432 checkflag=tmpscr->sflag[i];
2608 }
2609
2610
2/2
✓ Branch 0 taken 5747766 times.
✓ Branch 1 taken 1098 times.
5748864 if(checkflag==mfSTRIKE)
2611 {
2612
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2613 {
2614
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSTRIKE],tmpscr->secretcset[sSTRIKE]);
2615 906 }
2616 else
2617 {
2618 192 checkflag = strike_hint;
2619 }
2620 1098 }
2621
2622
20/36
✓ Branch 0 taken 5706470 times.
✓ Branch 1 taken 3148 times.
✓ Branch 2 taken 3618 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2064 times.
✓ Branch 5 taken 28640 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 33 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 5 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
5748864 switch(checkflag)
2623 {
2624 case 0:
2625 case mfZELDA:
2626 case mfPUSHED:
2627 case mfENEMY0:
2628 case mfENEMY1:
2629 case mfENEMY2:
2630 case mfENEMY3:
2631 case mfENEMY4:
2632 case mfENEMY5:
2633 case mfENEMY6:
2634 case mfENEMY7:
2635 case mfENEMY8:
2636 case mfENEMY9:
2637 case mfSINGLE:
2638 case mfSINGLE16:
2639 case mfNOENEMY:
2640 case mfTRAP_H:
2641 case mfTRAP_V:
2642 case mfTRAP_4:
2643 case mfTRAP_LR:
2644 case mfTRAP_UD:
2645 case mfNOGROUNDENEMY:
2646 case mfNOBLOCKS:
2647 case mfSCRIPT1:
2648 case mfSCRIPT2:
2649 case mfSCRIPT3:
2650 case mfSCRIPT4:
2651 case mfSCRIPT5:
2652 case mfSCRIPT6:
2653 case mfSCRIPT7:
2654 case mfSCRIPT8:
2655 case mfSCRIPT9:
2656 case mfSCRIPT10:
2657 case mfSCRIPT11:
2658 case mfSCRIPT12:
2659 case mfSCRIPT13:
2660 case mfSCRIPT14:
2661 case mfSCRIPT15:
2662 case mfSCRIPT16:
2663 case mfSCRIPT17:
2664 case mfSCRIPT18:
2665 case mfSCRIPT19:
2666 case mfSCRIPT20:
2667 case mfPITHOLE:
2668 case mfPITFALLFLOOR:
2669 case mfLAVA:
2670 case mfICE:
2671 case mfICEDAMAGE:
2672 case mfDAMAGE1:
2673 case mfDAMAGE2:
2674 case mfDAMAGE4:
2675 case mfDAMAGE8:
2676 case mfDAMAGE16:
2677 case mfDAMAGE32:
2678 case mfFREEZEALL:
2679 case mfFREZEALLANSFFCS:
2680 case mfFREEZEFFCSOLY:
2681 case mfSCRITPTW1TRIG:
2682 case mfSCRITPTW2TRIG:
2683 case mfSCRITPTW3TRIG:
2684 case mfSCRITPTW4TRIG:
2685 case mfSCRITPTW5TRIG:
2686 case mfSCRITPTW6TRIG:
2687 case mfSCRITPTW7TRIG:
2688 case mfSCRITPTW8TRIG:
2689 case mfSCRITPTW9TRIG:
2690 case mfSCRITPTW10TRIG:
2691 case mfTROWEL:
2692 case mfTROWELNEXT:
2693 case mfTROWELSPECIALITEM:
2694 case mfSLASHPOT:
2695 case mfLIFTPOT:
2696 case mfLIFTORSLASH:
2697 case mfLIFTROCK:
2698 case mfLIFTROCKHEAVY:
2699 case mfDROPITEM:
2700 case mfSPECIALITEM:
2701 case mfDROPKEY:
2702 case mfDROPLKEY:
2703 case mfDROPCOMPASS:
2704 case mfDROPMAP:
2705 case mfDROPBOSSKEY:
2706 case mfSPAWNNPC:
2707 case mfSWITCHHOOK:
2708 case mfSIDEVIEWLADDER:
2709 case mfSIDEVIEWPLATFORM:
2710 case mfNOENEMYSPAWN:
2711 case mfENEMYALL:
2712 case mfNOMIRROR:
2713 case mfUNSAFEGROUND:
2714 case mf168:
2715 case mf169:
2716 case mf170:
2717 case mf171:
2718 case mf172:
2719 case mf173:
2720 case mf174:
2721 case mf175:
2722 case mf176:
2723 case mf177:
2724 case mf178:
2725 case mf179:
2726 case mf180:
2727 case mf181:
2728 case mf182:
2729 case mf183:
2730 case mf184:
2731 case mf185:
2732 case mf186:
2733 case mf187:
2734 case mf188:
2735 case mf189:
2736 case mf190:
2737 case mf191:
2738 case mf192:
2739 case mf193:
2740 case mf194:
2741 case mf195:
2742 case mf196:
2743 case mf197:
2744 case mf198:
2745 case mf199:
2746 case mf200:
2747 case mf201:
2748 case mf202:
2749 case mf203:
2750 case mf204:
2751 case mf205:
2752 case mf206:
2753 case mf207:
2754 case mf208:
2755 case mf209:
2756 case mf210:
2757 case mf211:
2758 case mf212:
2759 case mf213:
2760 case mf214:
2761 case mf215:
2762 case mf216:
2763 case mf217:
2764 case mf218:
2765 case mf219:
2766 case mf220:
2767 case mf221:
2768 case mf222:
2769 case mf223:
2770 case mf224:
2771 case mf225:
2772 case mf226:
2773 case mf227:
2774 case mf228:
2775 case mf229:
2776 case mf230:
2777 case mf231:
2778 case mf232:
2779 case mf233:
2780 case mf234:
2781 case mf235:
2782 case mf236:
2783 case mf237:
2784 case mf238:
2785 case mf239:
2786 case mf240:
2787 case mf241:
2788 case mf242:
2789 case mf243:
2790 case mf244:
2791 case mf245:
2792 case mf246:
2793 case mf247:
2794 case mf248:
2795 case mf249:
2796 case mf250:
2797 case mf251:
2798 case mf252:
2799 case mf253:
2800 case mf254:
2801 case mfEXTENDED:
2802 5706470 break;
2803
2804 case mfPUSHUD:
2805 case mfPUSHLR:
2806 case mfPUSH4:
2807 case mfPUSHU:
2808 case mfPUSHD:
2809 case mfPUSHL:
2810 case mfPUSHR:
2811 case mfPUSHUDNS:
2812 case mfPUSHLRNS:
2813 case mfPUSH4NS:
2814 case mfPUSHUNS:
2815 case mfPUSHDNS:
2816 case mfPUSHLNS:
2817 case mfPUSHRNS:
2818 case mfPUSHUDINS:
2819 case mfPUSHLRINS:
2820 case mfPUSH4INS:
2821 case mfPUSHUINS:
2822 case mfPUSHDINS:
2823 case mfPUSHLINS:
2824 case mfPUSHRINS:
2825
3/4
✓ Branch 0 taken 1829 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1829 times.
3148 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2826
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1829 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1829 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1829 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2827 {
2828 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->undercombo,tmpscr->undercset);
2829 }
2830
2831
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3148 times.
3148 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2832
3/6
✓ Branch 0 taken 2438 times.
✓ Branch 1 taken 710 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 710 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3148 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2833 {
2834
2/2
✓ Branch 0 taken 1406 times.
✓ Branch 1 taken 1032 times.
2438 if(hints)
2835 {
2836
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch(combobuf[tmpscr->data[i]].type)
2837 {
2838 case cPUSH_HEAVY:
2839 case cPUSH_HW:
2840 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2841 72 tempitemx=x, tempitemy=y;
2842
2843
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(tempitem>-1)
2844 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2845
2846 72 break;
2847
2848 case cPUSH_HEAVY2:
2849 case cPUSH_HW2:
2850 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2851 63 tempitemx=x, tempitemy=y;
2852
2853
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 63 times.
63 if(tempitem>-1)
2854 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2855
2856 63 break;
2857 }
2858 1032 }
2859 2438 }
2860
2861 3148 break;
2862
2863 case mfWHISTLE:
2864
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2865 {
2866 tempitem=getItemID(itemsbuf,itype_whistle,1);
2867
2868 if(tempitem<0) break;
2869
2870 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2871 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2872 {
2873 tempitemx=x;
2874 tempitemy=y;
2875 }
2876
2877 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2878 }
2879
2880 2418 break;
2881
2882 //Why is this here?
2883 case mfFAIRY:
2884 case mfMAGICFAIRY:
2885 case mfALLFAIRY:
2886 if(hints)
2887 {
2888 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2889
2890 if(tempitem < 0) break;
2891
2892 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2893 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2894 {
2895 tempitemx=x;
2896 tempitemy=y;
2897 }
2898
2899 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2900 }
2901
2902 break;
2903
2904 case mfANYFIRE:
2905
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2906 {
2907
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sBCANDLE],tmpscr->secretcset[sBCANDLE]);
2908 252 }
2909 else
2910 {
2911 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2912
2913
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2914
2915
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2916
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2917 {
2918 189 tempitemx=x;
2919 189 tempitemy=y;
2920 189 }
2921
2922 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2923 }
2924
2925 504 break;
2926
2927 case mfSTRONGFIRE:
2928 if(!hints)
2929 {
2930 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sRCANDLE],tmpscr->secretcset[sRCANDLE]);
2931 }
2932 else
2933 {
2934 tempitem=getItemID(itemsbuf,itype_candle,2);
2935
2936 if(tempitem<0) break;
2937
2938 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2939 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2940 {
2941 tempitemx=x;
2942 tempitemy=y;
2943 }
2944
2945 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2946 }
2947
2948 break;
2949
2950 case mfMAGICFIRE:
2951 if(!hints)
2952 {
2953 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWANDFIRE],tmpscr->secretcset[sWANDFIRE]);
2954 }
2955 else
2956 {
2957 tempitem=getItemID(itemsbuf,itype_wand,1);
2958
2959 if(tempitem<0) break;
2960
2961 tempweapon=wFire;
2962
2963 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2964 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2965 {
2966 tempitemx=x;
2967 tempitemy=y;
2968 }
2969 else
2970 {
2971 tempweaponx=x;
2972 tempweapony=y;
2973 }
2974
2975 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2976 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2977 }
2978
2979 break;
2980
2981 case mfDIVINEFIRE:
2982 if(!hints)
2983 {
2984 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sDIVINEFIRE],tmpscr->secretcset[sDIVINEFIRE]);
2985 }
2986 else
2987 {
2988 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2989
2990 if(tempitem<0) break;
2991
2992 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2993 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2994 {
2995 tempitemx=x;
2996 tempitemy=y;
2997 }
2998
2999 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3000 }
3001
3002 break;
3003
3004 case mfARROW:
3005
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
3006 {
3007
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sARROW],tmpscr->secretcset[sARROW]);
3008 732 }
3009 else
3010 {
3011 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
3012
3013
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
3014
3015
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3016
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3017 {
3018 61 tempitemx=x;
3019 61 tempitemy=y;
3020 61 }
3021
3022 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3023 }
3024
3025 814 break;
3026
3027 case mfSARROW:
3028 if(!hints)
3029 {
3030 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSARROW],tmpscr->secretcset[sSARROW]);
3031 }
3032 else
3033 {
3034 tempitem=getItemID(itemsbuf,itype_arrow,2);
3035
3036 if(tempitem<0) break;
3037
3038 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3039 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3040 {
3041 tempitemx=x;
3042 tempitemy=y;
3043 }
3044
3045 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3046 }
3047
3048 break;
3049
3050 case mfGARROW:
3051 if(!hints)
3052 {
3053 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sGARROW],tmpscr->secretcset[sGARROW]);
3054 }
3055 else
3056 {
3057 tempitem=getItemID(itemsbuf,itype_arrow,3);
3058
3059 if(tempitem<0) break;
3060
3061 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3062 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3063 {
3064 tempitemx=x;
3065 tempitemy=y;
3066 }
3067
3068 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3069 }
3070
3071 break;
3072
3073 case mfBOMB:
3074
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 16 times.
33 if(!hints)
3075 {
3076
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sBOMB],tmpscr->secretcset[sBOMB]);
3077 16 }
3078 else
3079 {
3080 //tempitem=getItemID(itemsbuf,itype_bomb,1);
3081 17 tempweapon = wLitBomb;
3082
3083 //if (tempitem<0) break;
3084
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3085
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3086 {
3087 12 tempweaponx=x;
3088 12 tempweapony=y;
3089 12 }
3090
3091 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3092 }
3093
3094 33 break;
3095
3096 case mfSBOMB:
3097
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
3098 {
3099
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSBOMB],tmpscr->secretcset[sSBOMB]);
3100 48 }
3101 else
3102 {
3103 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
3104 //if (tempitem<0) break;
3105 48 tempweapon = wLitSBomb;
3106
3107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3108
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3109 {
3110 36 tempweaponx=x;
3111 36 tempweapony=y;
3112 36 }
3113
3114 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3115 }
3116
3117 96 break;
3118
3119 case mfARMOS_SECRET:
3120
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
3121 {
3122
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSTAIRS],tmpscr->secretcset[sSTAIRS]);
3123 12 }
3124 24 break;
3125
3126 case mfBRANG:
3127
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(!hints)
3128 {
3129 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sBRANG],tmpscr->secretcset[sBRANG]);
3130 }
3131 else
3132 {
3133 5 tempitem=getItemID(itemsbuf,itype_brang,1);
3134
3135
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
3136
3137
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3138
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3139 {
3140 4 tempitemx=x;
3141 4 tempitemy=y;
3142 4 }
3143
3144 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3145 }
3146
3147 5 break;
3148
3149 case mfMBRANG:
3150 if(!hints)
3151 {
3152 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sMBRANG],tmpscr->secretcset[sMBRANG]);
3153 }
3154 else
3155 {
3156 tempitem=getItemID(itemsbuf,itype_brang,2);
3157
3158 if(tempitem<0) break;
3159
3160 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3161 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3162 {
3163 tempitemx=x;
3164 tempitemy=y;
3165 }
3166
3167 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3168 }
3169
3170 break;
3171
3172 case mfFBRANG:
3173 if(!hints)
3174 {
3175 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sFBRANG],tmpscr->secretcset[sFBRANG]);
3176 }
3177 else
3178 {
3179 tempitem=getItemID(itemsbuf,itype_brang,3);
3180
3181 if(tempitem<0) break;
3182
3183 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3184 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3185 {
3186 tempitemx=x;
3187 tempitemy=y;
3188 }
3189
3190 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3191 }
3192
3193 break;
3194
3195 case mfWANDMAGIC:
3196 if(!hints)
3197 {
3198 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWANDMAGIC],tmpscr->secretcset[sWANDMAGIC]);
3199 }
3200 else
3201 {
3202 tempitem=getItemID(itemsbuf,itype_wand,1);
3203
3204 if(tempitem<0) break;
3205
3206 tempweapon=itemsbuf[tempitem].wpn3;
3207
3208 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3209 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3210 {
3211 tempitemx=x;
3212 tempitemy=y;
3213 }
3214 else
3215 {
3216 tempweaponx=x;
3217 tempweapony=y;
3218 --lens_hint_weapon[wMagic][4];
3219
3220 if(lens_hint_weapon[wMagic][4]<-8)
3221 {
3222 lens_hint_weapon[wMagic][4]=8;
3223 }
3224 }
3225
3226 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3227 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3228 }
3229
3230 break;
3231
3232 case mfREFMAGIC:
3233
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3234 {
3235 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sREFMAGIC],tmpscr->secretcset[sREFMAGIC]);
3236 }
3237 else
3238 {
3239 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3240
3241
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3242
3243 16 tempweapon=ewMagic;
3244
3245
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3246
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3247 {
3248 13 tempitemx=x;
3249 13 tempitemy=y;
3250 13 }
3251 else
3252 {
3253 3 tempweaponx=x;
3254 3 tempweapony=y;
3255
3256
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3257 {
3258 1 --lens_hint_weapon[ewMagic][4];
3259 1 }
3260 else
3261 {
3262 2 ++lens_hint_weapon[ewMagic][4];
3263 }
3264
3265
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3266 {
3267 lens_hint_weapon[ewMagic][2]=up;
3268 }
3269
3270
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3271 {
3272 2 lens_hint_weapon[ewMagic][2]=down;
3273 2 }
3274 }
3275
3276 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3277 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3278 }
3279
3280 16 break;
3281
3282 case mfREFFIREBALL:
3283
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3284 {
3285 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sREFFIREBALL],tmpscr->secretcset[sREFFIREBALL]);
3286 }
3287 else
3288 {
3289 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3290
3291
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3292
3293 16 tempweapon=ewFireball;
3294
3295
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3296
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3297 {
3298 12 tempitemx=x;
3299 12 tempitemy=y;
3300 12 tempweaponx=x;
3301 12 tempweapony=y;
3302 12 ++lens_hint_weapon[ewFireball][3];
3303
3304
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3305 {
3306 1 lens_hint_weapon[ewFireball][3]=-8;
3307 1 lens_hint_weapon[ewFireball][4]=8;
3308 1 }
3309
3310
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3311 {
3312 8 ++lens_hint_weapon[ewFireball][4];
3313 8 }
3314 else
3315 {
3316 4 --lens_hint_weapon[ewFireball][4];
3317 }
3318 12 }
3319
3320 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3321 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3322 }
3323
3324 16 break;
3325
3326 case mfSWORD:
3327
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3328 {
3329 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSWORD],tmpscr->secretcset[sSWORD]);
3330 }
3331 else
3332 {
3333 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3334
3335
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3336
3337
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3338
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3339 {
3340 5 tempitemx=x;
3341 5 tempitemy=y;
3342 5 }
3343
3344 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3345 }
3346
3347 7 break;
3348
3349 case mfWSWORD:
3350 if(!hints)
3351 {
3352 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWSWORD],tmpscr->secretcset[sWSWORD]);
3353 }
3354 else
3355 {
3356 tempitem=getItemID(itemsbuf,itype_sword,2);
3357
3358 if(tempitem<0) break;
3359
3360 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3361 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3362 {
3363 tempitemx=x;
3364 tempitemy=y;
3365 }
3366
3367 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3368 }
3369
3370 break;
3371
3372 case mfMSWORD:
3373 if(!hints)
3374 {
3375 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sMSWORD],tmpscr->secretcset[sMSWORD]);
3376 }
3377 else
3378 {
3379 tempitem=getItemID(itemsbuf,itype_sword,3);
3380
3381 if(tempitem<0) break;
3382
3383 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3384 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3385 {
3386 tempitemx=x;
3387 tempitemy=y;
3388 }
3389
3390 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3391 }
3392
3393 break;
3394
3395 case mfXSWORD:
3396 if(!hints)
3397 {
3398 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sXSWORD],tmpscr->secretcset[sXSWORD]);
3399 }
3400 else
3401 {
3402 tempitem=getItemID(itemsbuf,itype_sword,4);
3403
3404 if(tempitem<0) break;
3405
3406 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3407 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3408 {
3409 tempitemx=x;
3410 tempitemy=y;
3411 }
3412
3413 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3414 }
3415
3416 break;
3417
3418 case mfSWORDBEAM:
3419
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3420 {
3421 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSWORDBEAM],tmpscr->secretcset[sSWORDBEAM]);
3422 }
3423 else
3424 {
3425 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3426
3427
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3428
3429
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3430
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3431 {
3432 11 tempitemx=x;
3433 11 tempitemy=y;
3434 11 }
3435
3436 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3437 }
3438
3439 16 break;
3440
3441 case mfWSWORDBEAM:
3442 if(!hints)
3443 {
3444 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWSWORDBEAM],tmpscr->secretcset[sWSWORDBEAM]);
3445 }
3446 else
3447 {
3448 tempitem=getItemID(itemsbuf,itype_sword,2);
3449
3450 if(tempitem<0) break;
3451
3452 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3453 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3454 {
3455 tempitemx=x;
3456 tempitemy=y;
3457 }
3458
3459 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3460 }
3461
3462 break;
3463
3464 case mfMSWORDBEAM:
3465 if(!hints)
3466 {
3467 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sMSWORDBEAM],tmpscr->secretcset[sMSWORDBEAM]);
3468 }
3469 else
3470 {
3471 tempitem=getItemID(itemsbuf,itype_sword,3);
3472
3473 if(tempitem<0) break;
3474
3475 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3476 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3477 {
3478 tempitemx=x;
3479 tempitemy=y;
3480 }
3481
3482 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3483 }
3484
3485 break;
3486
3487 case mfXSWORDBEAM:
3488 if(!hints)
3489 {
3490 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sXSWORDBEAM],tmpscr->secretcset[sXSWORDBEAM]);
3491 }
3492 else
3493 {
3494 tempitem=getItemID(itemsbuf,itype_sword,4);
3495
3496 if(tempitem<0) break;
3497
3498 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3499 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3500 {
3501 tempitemx=x;
3502 tempitemy=y;
3503 }
3504
3505 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3506 }
3507
3508 break;
3509
3510 case mfHOOKSHOT:
3511
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3512 {
3513 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sHOOKSHOT],tmpscr->secretcset[sHOOKSHOT]);
3514 }
3515 else
3516 {
3517 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3518
3519
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3520
3521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3522
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3523 {
3524 12 tempitemx=x;
3525 12 tempitemy=y;
3526 12 }
3527
3528 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3529 }
3530
3531 17 break;
3532
3533 case mfWAND:
3534
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3535 {
3536 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWAND],tmpscr->secretcset[sWAND]);
3537 }
3538 else
3539 {
3540 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3541
3542
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3543
3544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3545
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3546 {
3547 28 tempitemx=x;
3548 28 tempitemy=y;
3549 28 }
3550
3551 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3552 }
3553
3554 35 break;
3555
3556 case mfHAMMER:
3557
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3558 {
3559 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sHAMMER],tmpscr->secretcset[sHAMMER]);
3560 }
3561 else
3562 {
3563 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3564
3565
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3566
3567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3568
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3569 {
3570 13 tempitemx=x;
3571 13 tempitemy=y;
3572 13 }
3573
3574 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3575 }
3576
3577 17 break;
3578
3579 case mfARMOS_ITEM:
3580 case mfDIVE_ITEM:
3581
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2064 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2064 if((!getmapflag() || (tmpscr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG3))
3582 {
3583 2064 putitem2(dest,x,y,tmpscr->catchall, lens_hint_item[tmpscr->catchall][0], lens_hint_item[tmpscr->catchall][1], 0);
3584 2064 }
3585 2064 break;
3586
3587 case 16:
3588 case 17:
3589 case 18:
3590 case 19:
3591 case 20:
3592 case 21:
3593 case 22:
3594 case 23:
3595 case 24:
3596 case 25:
3597 case 26:
3598 case 27:
3599 case 28:
3600 case 29:
3601 case 30:
3602 case 31:
3603
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 2610 times.
3618 if(!hints)
3604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2610 times.
5220 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))
3605 2610 putcombo(dest,x,y,tmpscr->secretcombo[checkflag-16+4],tmpscr->secretcset[checkflag-16+4]);
3606
3607 3618 break;
3608 case mfSECRETSNEXT:
3609 if(!hints)
3610 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))
3611 putcombo(dest,x,y,tmpscr->data[i]+1,tmpscr->cset[i]);
3612
3613 break;
3614
3615 case mfSTRIKE:
3616
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))
3617 {
3618 906 goto special;
3619 }
3620 else
3621 {
3622 break;
3623 }
3624
3625 28640 default: goto special;
3626
3627 special:
3628
8/8
✓ Branch 0 taken 14677 times.
✓ Branch 1 taken 14869 times.
✓ Branch 2 taken 473 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 441 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29546 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG4)))
3629 {
3630
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6549 times.
✓ Branch 2 taken 4913 times.
✓ Branch 3 taken 1636 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1636 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6549 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3631 {
3632 4913 rectfill(dest,x,y,x+15,y+15,WHITE);
3633 4913 }
3634 6549 }
3635
3636 29546 break;
3637 }
3638 5748864 }
3639 2874432 }
3640
3641
2/2
✓ Branch 0 taken 8166 times.
✓ Branch 1 taken 8166 times.
16332 if(layer)
3642 {
3643
2/2
✓ Branch 0 taken 7978 times.
✓ Branch 1 taken 188 times.
8166 if(tmpscr->door[0]==dWALK)
3644 188 rectfill(dest, 120, 16+playing_field_offset, 135, 31+playing_field_offset, WHITE);
3645
3646
2/2
✓ Branch 0 taken 7969 times.
✓ Branch 1 taken 197 times.
8166 if(tmpscr->door[1]==dWALK)
3647 197 rectfill(dest, 120, 144+playing_field_offset, 135, 159+playing_field_offset, WHITE);
3648
3649
2/2
✓ Branch 0 taken 8014 times.
✓ Branch 1 taken 152 times.
8166 if(tmpscr->door[2]==dWALK)
3650 152 rectfill(dest, 16, 80+playing_field_offset, 31, 95+playing_field_offset, WHITE);
3651
3652
2/2
✓ Branch 0 taken 7940 times.
✓ Branch 1 taken 226 times.
8166 if(tmpscr->door[3]==dWALK)
3653 226 rectfill(dest, 224, 80+playing_field_offset, 239, 95+playing_field_offset, WHITE);
3654
3655
2/2
✓ Branch 0 taken 8123 times.
✓ Branch 1 taken 43 times.
8166 if(tmpscr->door[0]==dBOMB)
3656 {
3657 43 showbombeddoor(dest, 0);
3658 43 }
3659
3660
2/2
✓ Branch 0 taken 8127 times.
✓ Branch 1 taken 39 times.
8166 if(tmpscr->door[1]==dBOMB)
3661 {
3662 39 showbombeddoor(dest, 1);
3663 39 }
3664
3665
1/2
✓ Branch 0 taken 8166 times.
✗ Branch 1 not taken.
8166 if(tmpscr->door[2]==dBOMB)
3666 {
3667 showbombeddoor(dest, 2);
3668 }
3669
3670
2/2
✓ Branch 0 taken 8129 times.
✓ Branch 1 taken 37 times.
8166 if(tmpscr->door[3]==dBOMB)
3671 {
3672 37 showbombeddoor(dest, 3);
3673 37 }
3674 8166 }
3675
3676
2/2
✓ Branch 0 taken 14298 times.
✓ Branch 1 taken 2034 times.
16332 if(tmpscr->stairx + tmpscr->stairy)
3677 {
3678
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if(!hints)
3679 {
3680
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))
3681 1123 putcombo(dest,tmpscr->stairx,tmpscr->stairy+playing_field_offset,tmpscr->secretcombo[sSTAIRS],tmpscr->secretcset[sSTAIRS]);
3682 1123 }
3683 else
3684 {
3685
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(tmpscr->flags&fWHISTLE)
3686 {
3687 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3688 48 int32_t tempitemx=-16;
3689 48 int32_t tempitemy=-16;
3690
3691
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3692
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3693 {
3694 24 tempitemx=tmpscr->stairx;
3695 24 tempitemy=tmpscr->stairy+playing_field_offset;
3696 24 }
3697
3698 48 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3699 48 }
3700 }
3701 2034 }
3702 }
3703 16332 }
3704
3705 BITMAP *lens_scr_d; // The "d" is for "destructible"!
3706
3707 7997 void draw_lens_over()
3708 {
3709 // Oh, what the heck.
3710 static BITMAP *lens_scr = NULL;
3711 static int32_t last_width = -1;
3712 7997 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3713
3714 // Only redraw the circle if the size has changed
3715
2/2
✓ Branch 0 taken 7987 times.
✓ Branch 1 taken 10 times.
7997 if(width != last_width)
3716 {
3717
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(lens_scr == NULL)
3718 {
3719 10 lens_scr = create_bitmap_ex(8,2*288,2*(240-playing_field_offset));
3720 10 }
3721
3722 10 clear_to_color(lens_scr, BLACK);
3723 10 circlefill(lens_scr, 288, 240-playing_field_offset, width, 0);
3724 10 circle(lens_scr, 288, 240-playing_field_offset, width+2, 0);
3725 10 circle(lens_scr, 288, 240-playing_field_offset, width+5, 0);
3726 10 last_width=width;
3727 10 }
3728
3729 7997 masked_blit(lens_scr, framebuf, 288-(HeroX()+8), 240-playing_field_offset-(HeroY()+8), 0, playing_field_offset, 256, 168);
3730 7997 do_primitives(framebuf, SPLAYER_LENS_OVER, tmpscr, 0, playing_field_offset);
3731 7997 }
3732
3733 //----------------------------------------------------------------
3734
3735 31111 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3736 {
3737 //recreating a big bitmap every frame is highly sluggish.
3738
4/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 31108 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
31111 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3739 31111 clear_to_color(wavebuf, BLACK);
3740 31111 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,224-original_playing_field_offset);
3741
3742 int32_t ofs;
3743 // int32_t amplitude=8;
3744 // int32_t wavelength=4;
3745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31111 times.
31111 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3746
3/6
✓ Branch 0 taken 31111 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31111 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 31111 times.
31111 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3747 31111 int32_t amp2=168;
3748
2/4
✓ Branch 0 taken 31111 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31111 times.
31111 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3749 31111 int32_t i=frame%amp2;
3750
3751
2/2
✓ Branch 0 taken 5226648 times.
✓ Branch 1 taken 31111 times.
5257759 for(int32_t j=0; j<168; j++)
3752 {
3753
3/4
✓ Branch 0 taken 2613324 times.
✓ Branch 1 taken 2613324 times.
✓ Branch 2 taken 2613324 times.
✗ Branch 3 not taken.
5226648 if(j&1 && interpol)
3754 {
3755 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3756 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3757 }
3758 else
3759 {
3760 5226648 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3761 }
3762
3763
1/2
✓ Branch 0 taken 5226648 times.
✗ Branch 1 not taken.
5226648 if(ofs)
3764 {
3765
2/2
✓ Branch 0 taken 1338021888 times.
✓ Branch 1 taken 5226648 times.
1343248536 for(int32_t k=0; k<256; k++)
3766 {
3767 1338021888 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3768 1338021888 }
3769 5226648 }
3770 5226648 }
3771 31111 }
3772
3773 4848 void draw_fuzzy(int32_t fuzz)
3774 // draws from right half of scrollbuf to framebuf
3775 {
3776 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3777 byte *start, *si, *di;
3778
3779
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4848 times.
4848 if(fuzz<1)
3780 fuzz = 1;
3781
3782 4848 xstep = 128%fuzz;
3783
3784
2/2
✓ Branch 0 taken 1010 times.
✓ Branch 1 taken 3838 times.
4848 if(xstep > 0)
3785 3838 xstep = fuzz-xstep;
3786
3787 4848 ystep = 112%fuzz;
3788
3789
2/2
✓ Branch 0 taken 1414 times.
✓ Branch 1 taken 3434 times.
4848 if(ystep > 0)
3790 3434 ystep = fuzz-ystep;
3791
3792 4848 firsty = 1;
3793
3794
2/2
✓ Branch 0 taken 4848 times.
✓ Branch 1 taken 174932 times.
179780 for(y=0; y<224;)
3795 {
3796 174932 start = &(scrollbuf->line[y][256]);
3797
3798
4/4
✓ Branch 0 taken 172508 times.
✓ Branch 1 taken 1088376 times.
✓ Branch 2 taken 1085952 times.
✓ Branch 3 taken 174932 times.
1260884 for(dy=0; dy<ystep && dy+y<224; dy++)
3799 {
3800 1085952 si = start;
3801 1085952 di = &(framebuf->line[y+dy][0]);
3802 1085952 i = xstep;
3803 1085952 firstx = 1;
3804
3805
2/2
✓ Branch 0 taken 278003712 times.
✓ Branch 1 taken 1085952 times.
279089664 for(dx=0; dx<256; dx++)
3806 {
3807 278003712 *(di++) = *si;
3808
3809
2/2
✓ Branch 0 taken 234248896 times.
✓ Branch 1 taken 43754816 times.
278003712 if(++i >= fuzz)
3810 {
3811
2/2
✓ Branch 0 taken 42668864 times.
✓ Branch 1 taken 1085952 times.
43754816 if(!firstx)
3812 42668864 si += fuzz;
3813 else
3814 {
3815 1085952 si += fuzz-xstep;
3816 1085952 firstx = 0;
3817 }
3818
3819 43754816 i = 0;
3820 43754816 }
3821 278003712 }
3822 1085952 }
3823
3824
2/2
✓ Branch 0 taken 170084 times.
✓ Branch 1 taken 4848 times.
174932 if(!firsty)
3825 170084 y += fuzz;
3826 else
3827 {
3828 4848 y += ystep;
3829 4848 ystep = fuzz;
3830 4848 firsty = 0;
3831 }
3832 }
3833 4848 }
3834
3835 9287337 void updatescr(bool allowwavy)
3836 {
3837
4/6
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 9287220 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 117 times.
✓ Branch 4 taken 117 times.
✗ Branch 5 not taken.
9287337 static BITMAP *wavybuf = create_bitmap_ex(8,256,224);
3838
4/6
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 9287220 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 117 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 117 times.
9287337 static BITMAP *panorama = create_bitmap_ex(8,256,224);
3839
3840
2/2
✓ Branch 0 taken 9260572 times.
✓ Branch 1 taken 26765 times.
9287337 if(toogam)
3841 {
3842 26765 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3843 26765 }
3844
3845
1/2
✓ Branch 0 taken 9287337 times.
✗ Branch 1 not taken.
9287337 if(Showpal)
3846 dump_pal(framebuf);
3847
3848
2/2
✓ Branch 0 taken 8986105 times.
✓ Branch 1 taken 301232 times.
9287337 if(!Playing)
3849 301232 black_opening_count=0;
3850
3851
2/2
✓ Branch 0 taken 9213945 times.
✓ Branch 1 taken 73392 times.
9287337 if(black_opening_count<0) //shape is opening up
3852 {
3853 73392 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3854
3855
2/4
✓ Branch 0 taken 73392 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 73392 times.
73392 if(Advance||(!Paused))
3856 {
3857 73392 ++black_opening_count;
3858 73392 }
3859 73392 }
3860
2/2
✓ Branch 0 taken 9187809 times.
✓ Branch 1 taken 26136 times.
9213945 else if(black_opening_count>0) //shape is closing
3861 {
3862 26136 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3863
3864
2/4
✓ Branch 0 taken 26136 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 26136 times.
26136 if(Advance||(!Paused))
3865 {
3866 26136 --black_opening_count;
3867 26136 }
3868 26136 }
3869
3870
3/4
✓ Branch 0 taken 9189317 times.
✓ Branch 1 taken 98020 times.
✓ Branch 2 taken 9189317 times.
✗ Branch 3 not taken.
9287337 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3871 {
3872 black_opening_shape = bosCIRCLE;
3873 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3874 refreshTints();
3875 refreshpal=true;
3876 }
3877
3878
2/2
✓ Branch 0 taken 9033135 times.
✓ Branch 1 taken 254202 times.
9287337 if(refreshpal)
3879 {
3880 254202 refreshpal=false;
3881 254202 RAMpal[253] = _RGB(0,0,0);
3882 254202 RAMpal[254] = _RGB(63,63,63);
3883 254202 hw_palette = &RAMpal;
3884 254202 update_hw_pal = true;
3885
3886 254202 create_rgb_table(&rgb_table, RAMpal, NULL);
3887 254202 create_zc_trans_table(&trans_table, RAMpal, 128, 128, 128);
3888 254202 memcpy(&trans_table2, &trans_table, sizeof(COLOR_MAP));
3889
3890
2/2
✓ Branch 0 taken 65075712 times.
✓ Branch 1 taken 254202 times.
65329914 for(int32_t q=0; q<PAL_SIZE; q++)
3891 {
3892 65075712 trans_table2.data[0][q] = q;
3893 65075712 trans_table2.data[q][q] = q;
3894 65075712 }
3895 254202 }
3896
3897 9287337 bool clearwavy = (wavy <= 0);
3898
3899
2/2
✓ Branch 0 taken 7655 times.
✓ Branch 1 taken 9279682 times.
9287337 if(wavy <= 0)
3900 {
3901 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3902 9279682 wavy = (DMaps[currdmap].flags&dmfWAVY ? 4 : 0);
3903 9279682 }
3904
3905 9287337 blit(framebuf, wavybuf, 0, 0, 0, 0, 256, 224);
3906
3907
6/6
✓ Branch 0 taken 31361 times.
✓ Branch 1 taken 9255976 times.
✓ Branch 2 taken 31239 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 31111 times.
9287337 if(wavy && Playing && allowwavy)
3908 {
3909 31111 draw_wavy(framebuf, wavybuf, wavy,false);
3910 31111 }
3911
3912
2/2
✓ Branch 0 taken 9279682 times.
✓ Branch 1 taken 7655 times.
9287337 if(clearwavy)
3913 9279682 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3914
2/4
✓ Branch 0 taken 7655 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7655 times.
7655 else if(Playing && !Paused)
3915 7655 wavy--; // Wavy was set by a script. Decrement it.
3916
3917
5/6
✓ Branch 0 taken 8986105 times.
✓ Branch 1 taken 301232 times.
✓ Branch 2 taken 259574 times.
✓ Branch 3 taken 8726531 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 259574 times.
9287337 if(Playing && msgpos && !screenscrolling)
3918 {
3919
1/2
✓ Branch 0 taken 259574 times.
✗ Branch 1 not taken.
259574 if(!(msg_bg_display_buf->clip))
3920 259574 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,168);
3921
1/2
✓ Branch 0 taken 259574 times.
✗ Branch 1 not taken.
259574 if(!(msg_portrait_display_buf->clip))
3922 259574 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,168);
3923
1/2
✓ Branch 0 taken 259574 times.
✗ Branch 1 not taken.
259574 if(!(msg_txt_display_buf->clip))
3924 259574 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,168);
3925 259574 }
3926
3927 /*
3928 if(!(msg_txt_display_buf->clip) && Playing && msgpos && !screenscrolling)
3929 {
3930 BITMAP* subBmp = 0;
3931 masked_blit(msg_txt_display_buf,subBmp,0,0,0,playing_field_offset,256,168);
3932 // masked_blit(msg_txt_display_buf,subBmp,0,playing_field_offset,256,168);
3933 draw_trans_sprite(framebuf, subBmp, 0, playing_field_offset);
3934 destroy_bitmap(subBmp);
3935 //void draw_sprite_ex(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t mode, int32_t flip);
3936 // masked_blit(msg_txt_display_buf,framebuf,0,0,0,playing_field_offset,256,168);
3937 //void masked_blit(BITMAP *source, BITMAP *dest, int32_t source_x, int32_t source_y, int32_t dest_x, int32_t dest_y, int32_t width, int32_t height);
3938 }
3939 */
3940
3941
2/2
✓ Branch 0 taken 9246280 times.
✓ Branch 1 taken 41057 times.
9287337 bool nosubscr = (tmpscr->flags3&fNOSUBSCR && !(tmpscr->flags3&fNOSUBSCROFFSET));
3942
3943
2/2
✓ Branch 0 taken 9250905 times.
✓ Branch 1 taken 36432 times.
9287337 if(nosubscr)
3944 {
3945 36432 rectfill(panorama,0,0,255,passive_subscreen_height/2,0);
3946 36432 rectfill(panorama,0,168+passive_subscreen_height/2,255,168+passive_subscreen_height-1,0);
3947 36432 blit(wavybuf,panorama,0,playing_field_offset,0,passive_subscreen_height/2,256,224-passive_subscreen_height);
3948 36432 }
3949
3950 //TODO: Optimize blit 'overcalls' -Gleeok
3951
2/2
✓ Branch 0 taken 36432 times.
✓ Branch 1 taken 9250905 times.
9287337 BITMAP *source = nosubscr ? panorama : wavybuf;
3952 9287337 blit(source,framebuf,0,0,0,0,256,224);
3953
3954 9287337 update_hw_screen();
3955 9287337 }
3956
3957 //----------------------------------------------------------------
3958
3959 static PALETTE syspal;
3960 int32_t onGUISnapshot()
3961 {
3962 char buf[200];
3963 int32_t num=0;
3964 do
3965 {
3966 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3967 }
3968 while(num<99999 && exists(buf));
3969
3970 if (!al_save_bitmap(buf, al_get_backbuffer(all_get_display())))
3971 InfoDialog("Error", "Failed to save snapshot").show();
3972
3973 return D_O_K;
3974 }
3975
3976 int32_t onNonGUISnapshot()
3977 {
3978 PALETTE temppal;
3979 get_palette(temppal);
3980 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3981
3982 char buf[200];
3983 int32_t num=0;
3984
3985 do
3986 {
3987 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3988 }
3989 while(num<99999 && exists(buf));
3990
3991 if (tmpscr->flags3&fNOSUBSCR && !(key[KEY_ALT]))
3992 {
3993 BITMAP *b = create_bitmap_ex(8,256,168);
3994 clear_to_color(b,0);
3995 blit(framebuf,b,0,passive_subscreen_height/2,0,0,256,168);
3996 alleg4_save_bitmap(b, SnapshotScale, buf);
3997 destroy_bitmap(b);
3998 }
3999 else
4000 {
4001 alleg4_save_bitmap(framebuf, SnapshotScale, buf, realpal?temppal:RAMpal);
4002 }
4003
4004 return D_O_K;
4005 }
4006
4007 int32_t onSnapshot()
4008 {
4009 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
4010 {
4011 onGUISnapshot();
4012 }
4013 else
4014 {
4015 onNonGUISnapshot();
4016 }
4017
4018 return D_O_K;
4019 }
4020
4021 int32_t onSaveMapPic()
4022 {
4023 int32_t mapres2 = 0;
4024 char buf[200];
4025 int32_t num=0;
4026 mapscr tmpscr_b[2];
4027 mapscr tmpscr_c[6];
4028 BITMAP* _screen_draw_buffer = NULL;
4029 _screen_draw_buffer = create_bitmap_ex(8,256,224);
4030 set_clip_state(_screen_draw_buffer,1);
4031
4032 for(int32_t i=0; i<6; ++i)
4033 {
4034 tmpscr_c[i] = tmpscr2[i];
4035 tmpscr2[i].zero_memory();
4036
4037 if(i>=2)
4038 {
4039 continue;
4040 }
4041
4042 tmpscr_b[i] = tmpscr[i];
4043 tmpscr[i].zero_memory();
4044 }
4045
4046 do
4047 {
4048 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
4049 }
4050 while(num<99999 && exists(buf));
4051
4052 BITMAP* mappic = NULL;
4053
4054
4055 bool done=false, redraw=true;
4056
4057 mappic = create_bitmap_ex(8,(256*16)>>mapres,(176*8)>>mapres);
4058
4059 if(!mappic)
4060 {
4061 enter_sys_pal();
4062 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
4063 exit_sys_pal();
4064 return D_O_K;;
4065 }
4066
4067 // draw the map
4068 set_clip_rect(_screen_draw_buffer, 0, 0, _screen_draw_buffer->w, _screen_draw_buffer->h);
4069
4070 for(int32_t y=0; y<8; y++)
4071 {
4072 for(int32_t x=0; x<16; x++)
4073 {
4074 if(!displayOnMap(x, y))
4075 {
4076 rectfill(_screen_draw_buffer, 0, 0, 255, 223, WHITE);
4077 }
4078 else
4079 {
4080 int32_t s = (y<<4) + x;
4081 loadscr2(1,s,-1);
4082
4083 for(int32_t i=0; i<6; i++)
4084 {
4085 if(tmpscr[1].layermap[i]<=0)
4086 continue;
4087
4088 tmpscr2[i]=TheMaps[(tmpscr[1].layermap[i]-1)*MAPSCRS+tmpscr[1].layerscreen[i]];
4089 }
4090
4091 if(XOR((tmpscr+1)->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_layer(_screen_draw_buffer, 0, 2, tmpscr+1, -256, playing_field_offset, 2);
4092
4093 if(XOR((tmpscr+1)->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_layer(_screen_draw_buffer, 0, 3, tmpscr+1, -256, playing_field_offset, 2);
4094
4095 if(lenscheck(tmpscr+1,0)) putscr(_screen_draw_buffer,256,0,tmpscr+1);
4096 do_layer(_screen_draw_buffer, 0, 1, tmpscr+1, -256, playing_field_offset, 2);
4097
4098 if(!XOR((tmpscr+1)->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_layer(_screen_draw_buffer, 0, 2, tmpscr+1, -256, playing_field_offset, 2);
4099
4100 putscrdoors(_screen_draw_buffer,256,0,tmpscr+1);
4101 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
4102 {
4103 do_layer(_screen_draw_buffer, -2, 0, tmpscr+1, -256, playing_field_offset, 2);
4104 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
4105 {
4106 do_layer(_screen_draw_buffer, -2, 1, tmpscr+1, -256, playing_field_offset, 2);
4107 do_layer(_screen_draw_buffer, -2, 2, tmpscr+1, -256, playing_field_offset, 2);
4108 }
4109 }
4110 do_layer(_screen_draw_buffer, -3, 0, tmpscr+1, -256, playing_field_offset, 2); // Freeform combos!
4111
4112 if(!XOR((tmpscr+1)->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_layer(_screen_draw_buffer, 0, 3, tmpscr+1, -256, playing_field_offset, 2);
4113
4114 do_layer(_screen_draw_buffer, 0, 4, tmpscr+1, -256, playing_field_offset, 2);
4115 do_layer(_screen_draw_buffer, -1, 0, tmpscr+1, -256, playing_field_offset, 2);
4116 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
4117 {
4118 do_layer(_screen_draw_buffer, -1, 1, tmpscr+1, -256, playing_field_offset, 2);
4119 do_layer(_screen_draw_buffer, -1, 2, tmpscr+1, -256, playing_field_offset, 2);
4120 }
4121 do_layer(_screen_draw_buffer, 0, 5, tmpscr+1, -256, playing_field_offset, 2);
4122 do_layer(_screen_draw_buffer, 0, 6, tmpscr+1, -256, playing_field_offset, 2);
4123
4124 }
4125
4126 stretch_blit(_screen_draw_buffer, mappic, 256, 0, 256, 176, x<<(8-mapres), (y*176)>>mapres, 256>>mapres, 176>>mapres);
4127 }
4128 }
4129
4130 for(int32_t i=0; i<6; ++i)
4131 {
4132 tmpscr2[i]=tmpscr_c[i];
4133
4134 if(i>=2)
4135 {
4136 continue;
4137 }
4138
4139 tmpscr[i]=tmpscr_b[i];
4140 }
4141
4142 save_bitmap(buf,mappic,RAMpal);
4143 destroy_bitmap(mappic);
4144 destroy_bitmap(_screen_draw_buffer);
4145 return D_O_K;
4146 }
4147
4148 14 void f_Quit(int32_t type)
4149 {
4150
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
14 if(type==qQUIT && !Playing)
4151 return;
4152
4153 14 bool from_menu = is_sys_pal;
4154
4155
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(!from_menu)
4156 {
4157 14 music_pause();
4158 14 pause_all_sfx();
4159 14 sys_mouse();
4160 14 }
4161 14 enter_sys_pal();
4162 14 clear_keybuf();
4163
4164
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13 times.
14 if (replay_version_check(0, 10))
4165 13 replay_poll();
4166
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (replay_is_replaying())
4167 14 replay_peek_quit();
4168
4169
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if (!replay_is_replaying())
4170 switch(type)
4171 {
4172 case qQUIT:
4173 onQuit();
4174 break;
4175
4176 case qRESET:
4177 onReset();
4178 break;
4179
4180 case qEXIT:
4181 onExit();
4182 break;
4183 }
4184
4185
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(Quit)
4186 {
4187 14 kill_sfx();
4188 14 music_stop();
4189 14 exit_sys_pal();
4190 14 update_hw_screen();
4191 14 }
4192 else
4193 {
4194 exit_sys_pal();
4195 if(!from_menu)
4196 {
4197 music_resume();
4198 resume_all_sfx();
4199 }
4200 }
4201
4202
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(!from_menu)
4203 14 game_mouse();
4204 14 eat_buttons();
4205
4206 14 zc_readrawkey(KEY_ESC);
4207
4208 14 zc_readrawkey(KEY_ENTER);
4209 14 }
4210
4211 //----------------------------------------------------------------
4212
4213 int32_t onNoWalls()
4214 {
4215 cheats_enqueue(Cheat::Walls);
4216 return D_O_K;
4217 }
4218
4219 int32_t onIgnoreSideview()
4220 {
4221 cheats_enqueue(Cheat::IgnoreSideView);
4222 return D_O_K;
4223 }
4224
4225 9287211 int32_t input_idle(bool checkmouse)
4226 {
4227 static int32_t mx, my, mz, mb;
4228
4229
4/6
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2461754 times.
✓ Branch 3 taken 6825457 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2461754 times.
11748965 if(keypressed() || zc_key_pressed() ||
4230
4/8
✓ Branch 0 taken 2461754 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2461754 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2461754 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2461754 times.
✗ Branch 7 not taken.
2461754 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4231 {
4232 6825457 idle_count = 0;
4233
4234
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6825457 times.
6825457 if(active_count < MAX_ACTIVE)
4235 {
4236 6825457 ++active_count;
4237 6825457 }
4238 6825457 }
4239
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2461754 times.
2461754 else if(idle_count < MAX_IDLE)
4240 {
4241 2461754 ++idle_count;
4242 2461754 active_count = 0;
4243 2461754 }
4244
4245 9287211 mx = mouse_x;
4246 9287211 my = mouse_y;
4247 9287211 mz = mouse_z;
4248 9287211 mb = mouse_b;
4249
4250 9287211 return idle_count;
4251 }
4252
4253 int32_t onGoFast()
4254 {
4255 cheats_enqueue(Cheat::Fast);
4256 return D_O_K;
4257 }
4258
4259 int32_t onKillCheat()
4260 {
4261 cheats_enqueue(Cheat::Kill);
4262 return D_O_K;
4263 }
4264
4265 int32_t onSecretsCheat()
4266 {
4267 cheats_enqueue(Cheat::TrigSecrets);
4268 return D_O_K;
4269 }
4270 int32_t onSecretsCheatPerm()
4271 {
4272 cheats_enqueue(Cheat::TrigSecretsPerm);
4273 return D_O_K;
4274 }
4275
4276 int32_t onShowLayer0()
4277 {
4278 show_layer_0 = !show_layer_0;
4279 return D_O_K;
4280 }
4281 int32_t onShowLayer1()
4282 {
4283 show_layer_1 = !show_layer_1;
4284 return D_O_K;
4285 }
4286 int32_t onShowLayer2()
4287 {
4288 show_layer_2 = !show_layer_2;
4289 return D_O_K;
4290 }
4291 int32_t onShowLayer3()
4292 {
4293 show_layer_3 = !show_layer_3;
4294 return D_O_K;
4295 }
4296 int32_t onShowLayer4()
4297 {
4298 show_layer_4 = !show_layer_4;
4299 return D_O_K;
4300 }
4301 int32_t onShowLayer5()
4302 {
4303 show_layer_5 = !show_layer_5;
4304 return D_O_K;
4305 }
4306 int32_t onShowLayer6()
4307 {
4308 show_layer_6 = !show_layer_6;
4309 return D_O_K;
4310 }
4311 int32_t onShowLayerO()
4312 {
4313 show_layer_over=!show_layer_over;
4314 return D_O_K;
4315 }
4316 int32_t onShowLayerP()
4317 {
4318 show_layer_push=!show_layer_push;
4319 return D_O_K;
4320 }
4321 int32_t onShowLayerS()
4322 {
4323 show_sprites=!show_sprites;
4324 return D_O_K;
4325 }
4326 int32_t onShowLayerF()
4327 {
4328 show_ffcs=!show_ffcs;
4329 return D_O_K;
4330 }
4331 int32_t onShowLayerW()
4332 {
4333 show_walkflags=!show_walkflags;
4334 if(show_walkflags)
4335 show_effectflags = false;
4336 return D_O_K;
4337 }
4338 int32_t onShowLayerE()
4339 {
4340 show_effectflags=!show_effectflags;
4341 if(show_effectflags)
4342 show_walkflags = false;
4343 return D_O_K;
4344 }
4345 int32_t onShowFFScripts()
4346 {
4347 show_ff_scripts=!show_ff_scripts;
4348 return D_O_K;
4349 }
4350 int32_t onShowHitboxes()
4351 {
4352 show_hitboxes=!show_hitboxes;
4353 return D_O_K;
4354 }
4355 int32_t onShowInfoOpacity()
4356 {
4357 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4358 zc_set_config("zc","debug_info_opacity",info_opacity);
4359 return D_O_K;
4360 }
4361
4362 int32_t onLightSwitch()
4363 {
4364 cheats_enqueue(Cheat::Light);
4365 return D_O_K;
4366 }
4367
4368 int32_t onGoTo();
4369 int32_t onGoToComplete();
4370
4371 9287211 bool handle_close_btn_quit()
4372 {
4373
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(close_button_quit)
4374 {
4375 close_button_quit=false;
4376 f_Quit(qEXIT);
4377 }
4378 9287211 return (exiting_program = Quit==qEXIT);
4379 }
4380
4381 9287211 void syskeys()
4382 {
4383 9287211 update_system_keys();
4384
4385 int32_t oldtitle_version;
4386
4387 9287211 poll_joystick();
4388
4389 9287211 handle_close_btn_quit();
4390
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
9287211 if(Quit == qEXIT) return;
4391
4392
2/10
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9287211 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
9287211 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4393 {
4394 System();
4395 }
4396
4397 9287211 mouse_down=gui_mouse_b();
4398
4399
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(zc_read_system_key(KEY_F1))
4400 {
4401 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4402 {
4403 halt=!halt;
4404 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4405 }
4406 else
4407 {
4408 Throttlefps=!Throttlefps;
4409 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4410 }
4411 }
4412
4413 // if(zc_readkey(KEY_F1)) Vsync=!Vsync;
4414 /*
4415 if(zc_readkey(KEY_F1)) set_bit(QHeader.rules4,qr4_NEWENEMYTILES,
4416 1-((get_bit(QHeader.rules4,qr4_NEWENEMYTILES))));
4417 */
4418
4419
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(zc_read_system_key(KEY_F2))
4420 {
4421 ShowFPS=!ShowFPS;
4422 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4423 }
4424
4425
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9287211 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4426
4427
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9287211 if(zc_read_system_key(KEY_F4) && Playing)
4428 {
4429 Paused=true;
4430 Advance=true;
4431 }
4432
4433
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(zc_read_system_key(KEY_F6)) onTryQuit();
4434
4435 #ifndef ALLEGRO_MACOSX
4436
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4437
4438
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4439 #else
4440 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4441
4442 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4443 #endif
4444
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
9287211 if(zc_read_system_key(KEY_F5)&&(Playing && currscr<128 && DMaps[currdmap].flags&dmfVIEWMAP)) onSaveMapPic();
4445
4446
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if (zc_read_system_key(KEY_F12))
4447 {
4448 onSnapshot();
4449 }
4450
4451
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9287211 if(debug_enabled && zc_read_system_key(KEY_TAB))
4452 set_debug(!get_debug());
4453
4454
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(CheatModifierKeys())
4455 {
4456 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4457 {
4458 if(!bindable_cheat(c))
4459 continue;
4460 if(get_debug() || cheat >= cheat_lvl(c))
4461 {
4462 if(checkcheat(c))
4463 cheats_hit_bind(c);
4464 }
4465 }
4466 }
4467
4468
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(volkeys)
4469 {
4470 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4471
4472 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4473
4474 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4475
4476 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4477 }
4478
4479
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
9287211 if(!get_debug() || !SystemKeys || replay_is_replaying())
4480 9287211 goto bottom;
4481
4482 if(zc_readkey(KEY_D))
4483 {
4484 details = !details;
4485 rectfill(screen,0,0,319,7,BLACK);
4486 rectfill(screen,0,8,31,239,BLACK);
4487 rectfill(screen,288,8,319,239,BLACK);
4488 rectfill(screen,32,232,287,239,BLACK);
4489 }
4490
4491 if(zc_readkey(KEY_P)) Paused=!Paused;
4492
4493 //if(zc_readkey(KEY_P)) centerHero();
4494 if(zc_readkey(KEY_A))
4495 {
4496 Paused=true;
4497 Advance=true;
4498 }
4499
4500 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4501 #ifndef ALLEGRO_MACOSX
4502 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4503
4504 if(zc_readkey(KEY_F7))
4505 {
4506 Matrix(ss_speed, ss_density, 0);
4507 game_pal();
4508 }
4509 #else
4510 // The reason these are different on Mac in the first place is that
4511 // the OS doesn't let us use F9 and F10...
4512 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4513
4514 if(zc_readkey(KEY_F9))
4515 {
4516 Matrix(ss_speed, ss_density, 0);
4517 game_pal();
4518 }
4519 #endif
4520 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4521 {
4522 //change containers
4523 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4524 {
4525 //magic containers
4526 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4527 {
4528 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4529 }
4530 else
4531 {
4532 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4533 }
4534 }
4535 else
4536 {
4537 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4538 {
4539 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4540 }
4541 else
4542 {
4543 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4544 }
4545 }
4546 }
4547
4548 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4549 {
4550 //change containers
4551 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4552 {
4553 //magic containers
4554 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4555 {
4556 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4557 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4558 //heart containers
4559 }
4560 else
4561 {
4562 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4563 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4564 }
4565 }
4566 else
4567 {
4568 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4569 {
4570 game->set_magic(zc_max(game->get_magic()-1,0));
4571 }
4572 else
4573 {
4574 game->set_life(zc_max(game->get_life()-1,0));
4575 }
4576 }
4577 }
4578
4579 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4580
4581 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4582
4583 verifyBothWeapons();
4584
4585 bottom:
4586
4587
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(input_idle(true) > after_time())
4588 {
4589 Matrix(ss_speed, ss_density, 0);
4590 game_pal();
4591 }
4592 9287211 }
4593
4594 708292 void checkQuitKeys()
4595 {
4596 #ifndef ALLEGRO_MACOSX
4597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 708292 times.
708292 if(key[KEY_F9]) f_Quit(qRESET);
4598
4599
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 708292 times.
708292 if(key[KEY_F10]) f_Quit(qEXIT);
4600 #else
4601 if(key[KEY_F7]) f_Quit(qRESET);
4602
4603 if(key[KEY_F8]) f_Quit(qEXIT);
4604 #endif
4605 708292 }
4606
4607 9287211 bool CheatModifierKeys()
4608 {
4609 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4610 // to trigger cheats.
4611
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if (replay_is_replaying())
4612 9287211 return false;
4613
4614 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4615 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4616 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4617 {
4618 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4619 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4620 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4621 {
4622 return true;
4623 }
4624 }
4625 return false;
4626 9287211 }
4627
4628 //99:05:54, for some reason?
4629 #define OLDMAXTIME 21405240
4630 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4631 #define MAXTIME 1944000000
4632
4633 9287337 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4634 {
4635
1/2
✓ Branch 0 taken 9287337 times.
✗ Branch 1 not taken.
9287337 if(zcmusic!=NULL)
4636 {
4637 zcmusic_poll();
4638 }
4639 9287337 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4640
4641 9287337 updatescr(allowwavy);
4642
4643 9287337 Advance=false;
4644
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9287337 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9287337 times.
9287337 while(Paused && !Advance && !Quit)
4645 {
4646 // have to call this, otherwise we'll get an infinite loop
4647 syskeys();
4648 if(allowF6Script)
4649 {
4650 FFCore.runF6Engine();
4651 }
4652 zc_throttle_fps();
4653
4654 #ifdef _WIN32
4655
4656 if(use_dwm_flush)
4657 {
4658 do_DwmFlush();
4659 }
4660
4661 #endif
4662
4663 // to keep music playing
4664 if(zcmusic!=NULL)
4665 {
4666 zcmusic_poll();
4667 }
4668
4669 update_hw_screen();
4670 }
4671
4672
2/2
✓ Branch 0 taken 9287225 times.
✓ Branch 1 taken 112 times.
9287337 if(Quit)
4673 112 return;
4674
4675
3/4
✓ Branch 0 taken 8986096 times.
✓ Branch 1 taken 301129 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8986096 times.
9287225 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4676 8986096 game->change_time(1);
4677
4678 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4679
4680 9287225 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4681
2/2
✓ Branch 0 taken 20428 times.
✓ Branch 1 taken 9266797 times.
9287225 if (replay_version_check(0, 16))
4682 9266797 should_reset_down_state = replay_version_check(11, 16);
4683
2/2
✓ Branch 0 taken 6949680 times.
✓ Branch 1 taken 2337545 times.
9287225 if (should_reset_down_state)
4684 {
4685
2/2
✓ Branch 0 taken 42075810 times.
✓ Branch 1 taken 2337545 times.
44413355 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4686 42075810 down_control_states[i] = raw_control_state[i];
4687 2337545 }
4688
4689
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 9287211 times.
9287225 if (replay_is_active())
4690 {
4691
2/2
✓ Branch 0 taken 1270449 times.
✓ Branch 1 taken 8016762 times.
9287211 if (replay_version_check(3))
4692 8016762 replay_poll();
4693
4694
4/4
✓ Branch 0 taken 6946098 times.
✓ Branch 1 taken 2341113 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 6845563 times.
9287211 if (replay_version_check(11) || replay_version_check(6, 8))
4695 2441648 replay_peek_input();
4696 9287211 }
4697
4698 9287225 load_control_called_this_frame = false;
4699
4700 9287225 poll_keyboard();
4701 9287225 update_keys();
4702
4703 9287225 ++frame;
4704
4705
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 9287211 times.
9287225 if (replay_is_replaying())
4706 9287211 replay_do_cheats();
4707 9287225 syskeys();
4708
4709 // The mouse variables can change from the mouse thread at anytime during a frame,
4710 // so save the result at the start so that replaying is consistent.
4711 9287225 script_mouse_x = gui_mouse_x();
4712 9287225 script_mouse_y = gui_mouse_y();
4713 9287225 script_mouse_z = mouse_z;
4714 9287225 script_mouse_b = mouse_b;
4715
4716 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4717 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4718 // approach here means it doesn't matter which call adds the cheat.
4719 9287225 cheats_execute_queued();
4720
4721
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 9287211 times.
9287225 if (replay_is_replaying())
4722 9287211 replay_peek_quit();
4723
2/2
✓ Branch 0 taken 9287211 times.
✓ Branch 1 taken 14 times.
9287225 if (GameFlags & GAMEFLAG_TRYQUIT)
4724 14 replay_step_quit(0);
4725
2/2
✓ Branch 0 taken 2934 times.
✓ Branch 1 taken 9284291 times.
9287225 if(allowF6Script)
4726 9284291 FFCore.runF6Engine();
4727
2/2
✓ Branch 0 taken 301 times.
✓ Branch 1 taken 9286924 times.
9287225 if (Quit)
4728 301 replay_step_quit(Quit);
4729 // Someday... maybe install a Turbo button here?
4730 9287225 zc_throttle_fps();
4731
4732 #ifdef _WIN32
4733
4734 if(use_dwm_flush)
4735 {
4736 do_DwmFlush();
4737 }
4738
4739 #endif
4740
4741 //textprintf_ex(screen,font,0,72,254,BLACK,"%d %d", lastentrance, lastentrance_dmap);
4742
2/2
✓ Branch 0 taken 68758 times.
✓ Branch 1 taken 9218467 times.
9287225 if(sfxcleanup)
4743 9218467 sfx_cleanup();
4744
4745 9287225 jit_poll();
4746
4747 #ifdef __EMSCRIPTEN__
4748 // Yield the main thread back to the browser occasionally.
4749 if (is_headless())
4750 {
4751 static int rate = 10000;
4752 static int force_yield = rate;
4753 if (force_yield++ >= rate)
4754 {
4755 force_yield = 0;
4756 emscripten_sleep(0);
4757 }
4758 }
4759 #endif
4760
4761
4/6
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 9287108 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 117 times.
✓ Branch 4 taken 117 times.
✗ Branch 5 not taken.
9287225 static bool test_mode_auto_restart = zc_get_config("zeldadx", "test_mode_auto_restart", false);
4762
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9287225 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9287225 if (zqtesting_mode && test_mode_auto_restart)
4763 {
4764 static auto last_write_time = fs::last_write_time(qstpath);
4765 static auto last_check = std::chrono::system_clock::now();
4766
4767 if (std::chrono::system_clock::now() - last_check > 200ms)
4768 {
4769 last_check = std::chrono::system_clock::now();
4770 auto write_time = fs::last_write_time(qstpath);
4771 if (last_write_time != write_time)
4772 {
4773 last_write_time = write_time;
4774 disableClickToFreeze = false;
4775 Quit = qRESET;
4776 replay_quit();
4777 }
4778 }
4779 }
4780 9287337 }
4781
4782 101 void zapout()
4783 {
4784 101 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
4785 101 blit(framebuf,scrollbuf,0,0,256,0,256,224);
4786
4787 101 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4788 101 script_drawing_commands.Clear();
4789
4790 // zap out
4791
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 2424 times.
2525 for(int32_t i=1; i<=24; i++)
4792 {
4793 2424 draw_fuzzy(i);
4794 2424 advanceframe(true);
4795
4796
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2424 times.
2424 if(Quit)
4797 {
4798 break;
4799 }
4800 2424 }
4801 101 }
4802
4803 101 void zapin()
4804 {
4805 101 FFCore.warpScriptCheck();
4806 101 draw_screen(tmpscr);
4807 101 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
4808 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
4809 101 blit(framebuf,scrollbuf,0,0,256,0,256,224);
4810
4811 // zap out
4812 101 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4813
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 2424 times.
2525 for(int32_t i=24; i>=1; i--)
4814 {
4815 2424 draw_fuzzy(i);
4816 2424 advanceframe(true);
4817
4818
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2424 times.
2424 if(Quit)
4819 {
4820 break;
4821 }
4822 2424 }
4823 101 }
4824
4825
4826 65 void wavyout(bool showhero)
4827 {
4828 65 draw_screen(tmpscr, showhero);
4829 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
4830
4831 65 BITMAP *wavebuf = create_bitmap_ex(8,288,224);
4832 65 clear_to_color(wavebuf,0);
4833 65 blit(framebuf,wavebuf,0,0,16,0,256,224);
4834
4835 static PALETTE wavepal;
4836
4837 int32_t ofs;
4838 65 int32_t amplitude=8;
4839
4840 65 int32_t wavelength=4;
4841 65 double palpos=0, palstep=4, palstop=126;
4842
4843 65 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4844
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 2730 times.
2795 for(int32_t i=0; i<168; i+=wavelength)
4845 {
4846
2/2
✓ Branch 0 taken 698880 times.
✓ Branch 1 taken 2730 times.
701610 for(int32_t l=0; l<256; l++)
4847 {
4848 698880 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(63-RAMpal[l].r))),0,63);
4849 698880 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(63-RAMpal[l].g))),0,63);
4850 698880 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(63-RAMpal[l].b))),0,63);
4851 698880 }
4852
4853 2730 palpos+=palstep;
4854
4855
1/2
✓ Branch 0 taken 2730 times.
✗ Branch 1 not taken.
2730 if(palpos>=0)
4856 {
4857 2730 hw_palette = &wavepal;
4858 2730 update_hw_pal = true;
4859 2730 }
4860 else
4861 {
4862 hw_palette = &RAMpal;
4863 update_hw_pal = true;
4864 }
4865
4866
2/2
✓ Branch 0 taken 458640 times.
✓ Branch 1 taken 2730 times.
461370 for(int32_t j=0; j+playing_field_offset<224; j++)
4867 {
4868
2/2
✓ Branch 0 taken 117411840 times.
✓ Branch 1 taken 458640 times.
117870480 for(int32_t k=0; k<256; k++)
4869 {
4870 117411840 ofs=0;
4871
4872
4/4
✓ Branch 0 taken 57308160 times.
✓ Branch 1 taken 60103680 times.
✓ Branch 2 taken 28654080 times.
✓ Branch 3 taken 28654080 times.
117411840 if((j<i)&&(j&1))
4873 {
4874 28654080 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/168.0))*amplitude);
4875 28654080 }
4876
4877 117411840 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4878 117411840 }
4879 458640 }
4880
4881 2730 advanceframe(true);
4882
4883 // animate_combos();
4884
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2730 times.
2730 if(Quit)
4885 break;
4886 2730 }
4887
4888 65 destroy_bitmap(wavebuf);
4889 65 }
4890
4891 65 void wavyin()
4892 {
4893 65 draw_screen(tmpscr);
4894 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
4895
4896 65 BITMAP *wavebuf = create_bitmap_ex(8,288,224);
4897 65 clear_to_color(wavebuf,0);
4898 65 blit(framebuf,wavebuf,0,0,16,0,256,224);
4899
4900 static PALETTE wavepal;
4901
4902 //Breaks dark rooms.
4903 //In any case I don't think we need this, since palette is already loaded in doWarp() (famous last words...) -DD
4904 /*
4905 loadfullpal();
4906 loadlvlpal(DMaps[currdmap].color);
4907 ringcolor(false);
4908 */
4909 65 refreshpal=false;
4910 int32_t ofs;
4911 65 int32_t amplitude=8;
4912 65 int32_t wavelength=4;
4913 65 double palpos=168, palstep=4, palstop=126;
4914
4915 65 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4916
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 2730 times.
2795 for(int32_t i=0; i<168; i+=wavelength)
4917 {
4918
2/2
✓ Branch 0 taken 698880 times.
✓ Branch 1 taken 2730 times.
701610 for(int32_t l=0; l<256; l++)
4919 {
4920 698880 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(63-RAMpal[l].r))),0,63);
4921 698880 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(63-RAMpal[l].g))),0,63);
4922 698880 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(63-RAMpal[l].b))),0,63);
4923 698880 }
4924
4925 2730 palpos-=palstep;
4926
4927
1/2
✓ Branch 0 taken 2730 times.
✗ Branch 1 not taken.
2730 if(palpos>=0)
4928 {
4929 2730 hw_palette = &wavepal;
4930 2730 update_hw_pal = true;
4931 2730 }
4932 else
4933 {
4934 hw_palette = &RAMpal;
4935 update_hw_pal = true;
4936 }
4937
4938
2/2
✓ Branch 0 taken 458640 times.
✓ Branch 1 taken 2730 times.
461370 for(int32_t j=0; j+playing_field_offset<224; j++)
4939 {
4940
2/2
✓ Branch 0 taken 117411840 times.
✓ Branch 1 taken 458640 times.
117870480 for(int32_t k=0; k<256; k++)
4941 {
4942 117411840 ofs=0;
4943
4944
4/4
✓ Branch 0 taken 59404800 times.
✓ Branch 1 taken 58007040 times.
✓ Branch 2 taken 30051840 times.
✓ Branch 3 taken 29352960 times.
117411840 if((j<(167-i))&&(j&1))
4945 {
4946 29352960 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/168.0))*amplitude);
4947 29352960 }
4948
4949 117411840 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4950 117411840 }
4951 458640 }
4952
4953 2730 advanceframe(true);
4954 // animate_combos();
4955
4956
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2730 times.
2730 if(Quit)
4957 break;
4958 2730 }
4959
4960 65 destroy_bitmap(wavebuf);
4961 65 }
4962
4963 2168 void blackscr(int32_t fcnt,bool showsubscr)
4964 {
4965 2168 reset_pal_cycling();
4966 2168 script_drawing_commands.Clear();
4967
4968 2168 FFCore.warpScriptCheck();
4969 2168 bool showtime = game->should_show_time();
4970
2/2
✓ Branch 0 taken 2168 times.
✓ Branch 1 taken 64970 times.
67138 while(fcnt>0)
4971 {
4972 64970 clear_bitmap(framebuf);
4973
4974
2/2
✓ Branch 0 taken 25080 times.
✓ Branch 1 taken 39890 times.
64970 if(showsubscr)
4975 {
4976 39890 put_passive_subscr(framebuf,0,passive_subscreen_offset,showtime,sspUP);
4977
3/4
✓ Branch 0 taken 39890 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 750 times.
✓ Branch 3 taken 39140 times.
39890 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4978 {
4979 750 do_script_draws(framebuf, tmpscr, 0, playing_field_offset);
4980 750 }
4981 39890 }
4982
4983 64970 advanceframe(true);
4984
4985
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64970 times.
64970 if(Quit)
4986 break;
4987
4988 64970 --fcnt;
4989 }
4990 2168 }
4991
4992 1013 void openscreen(int32_t shape)
4993 {
4994 1013 reset_pal_cycling();
4995 1013 black_opening_count=0;
4996
4997
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 913 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 100 times.
1013 if(COOLSCROLL || shape>-1)
4998 {
4999 913 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
5000 913 return;
5001 }
5002 else
5003 {
5004 100 Hero.setDontDraw(true);
5005 100 show_subscreen_dmap_dots=false;
5006 100 show_subscreen_numbers=false;
5007 // show_subscreen_items=false;
5008 100 show_subscreen_life=false;
5009 }
5010
5011 100 int32_t x=128;
5012
5013 100 FFCore.warpScriptCheck();
5014
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 8000 times.
8100 for(int32_t i=0; i<80; i++)
5015 {
5016 8000 draw_screen(tmpscr);
5017 //? draw_screen already draws the subscreen -DD
5018 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
5019 8000 x=128-(((i*128/80)/8)*8);
5020
5021
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8000 times.
8000 if(x>0)
5022 {
5023 8000 rectfill(framebuf,0,playing_field_offset,x,167+playing_field_offset,0);
5024 8000 rectfill(framebuf,256-x,playing_field_offset,255,167+playing_field_offset,0);
5025 8000 }
5026
5027 8000 advanceframe(true);
5028
5029
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8000 times.
8000 if(Quit)
5030 {
5031 break;
5032 }
5033 8000 }
5034
5035 100 Hero.setDontDraw(false);
5036 100 show_subscreen_items=true;
5037 100 show_subscreen_dmap_dots=true;
5038 1013 }
5039
5040 void closescreen(int32_t shape)
5041 {
5042 reset_pal_cycling();
5043 black_opening_count=0;
5044
5045 if(COOLSCROLL || shape>-1)
5046 {
5047 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
5048 return;
5049 }
5050 else
5051 {
5052 Hero.setDontDraw(true);
5053 show_subscreen_dmap_dots=false;
5054 show_subscreen_numbers=false;
5055 // show_subscreen_items=false;
5056 show_subscreen_life=false;
5057 }
5058
5059 int32_t x=128;
5060
5061 FFCore.warpScriptCheck();
5062 for(int32_t i=79; i>=0; --i)
5063 {
5064 draw_screen(tmpscr);
5065 //? draw_screen already draws the subscreen -DD
5066 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
5067 x=128-(((i*128/80)/8)*8);
5068
5069 if(x>0)
5070 {
5071 rectfill(framebuf,0,playing_field_offset,x,167+playing_field_offset,0);
5072 rectfill(framebuf,256-x,playing_field_offset,255,167+playing_field_offset,0);
5073 }
5074
5075 advanceframe(true);
5076
5077 if(Quit)
5078 {
5079 break;
5080 }
5081 }
5082
5083 Hero.setDontDraw(false);
5084 show_subscreen_items=true;
5085 show_subscreen_dmap_dots=true;
5086 }
5087
5088 179 int32_t TriforceCount()
5089 {
5090 179 int32_t c=0;
5091
5092
2/2
✓ Branch 0 taken 1432 times.
✓ Branch 1 taken 179 times.
1611 for(int32_t i=1; i<=8; i++)
5093
2/2
✓ Branch 0 taken 388 times.
✓ Branch 1 taken 1044 times.
2476 if(game->lvlitems[i]&liTRIFORCE)
5094 1044 ++c;
5095
5096 179 return c;
5097 }
5098
5099 int32_t onCustomGame()
5100 {
5101 int32_t file = getsaveslot();
5102
5103 if(file < 0)
5104 return D_O_K;
5105
5106 bool ret = (custom_game(file)!=0);
5107 return ret ? D_CLOSE : D_O_K;
5108 }
5109
5110 int32_t onContinue()
5111 {
5112 return D_CLOSE;
5113 }
5114
5115 int32_t onEsc() // Unused?? -L
5116 {
5117 return zc_getrawkey(KEY_ESC, true)?D_CLOSE:D_O_K;
5118 }
5119
5120 int32_t onVsync()
5121 {
5122 Throttlefps = !Throttlefps;
5123 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
5124 return D_O_K;
5125 }
5126
5127 int32_t onWinPosSave()
5128 {
5129 SaveWinPos = !SaveWinPos;
5130 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
5131 return D_O_K;
5132 }
5133 int32_t onIntegerScaling()
5134 {
5135 scaleForceInteger = !scaleForceInteger;
5136 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
5137 return D_O_K;
5138 }
5139 int32_t onStretchGame()
5140 {
5141 stretchGame = !stretchGame;
5142 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
5143 return D_O_K;
5144 }
5145
5146 int32_t onClickToFreeze()
5147 {
5148 ClickToFreeze = !ClickToFreeze;
5149 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
5150 return D_O_K;
5151 }
5152
5153 int32_t OnSaveZCConfig()
5154 {
5155 if(jwin_alert3(
5156 "Save Configuration",
5157 "Are you sure that you wish to save your present configuration settings?",
5158 "This will overwrite your prior settings!",
5159 NULL,
5160 "&Yes",
5161 "&No",
5162 NULL,
5163 'y',
5164 'n',
5165 0,
5166 get_zc_font(font_lfont)) == 1)
5167 {
5168 save_game_configs();
5169 return D_O_K;
5170 }
5171 else return D_O_K;
5172 }
5173
5174 int32_t OnnClearQuestDir()
5175 {
5176 auto current_path = fs::current_path() / "quests";
5177 if(jwin_alert3(
5178 "Clear Current Directory Cache",
5179 "Are you sure that you wish to reset where ZC Player looks for quests?",
5180 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
5181 NULL,
5182 "&Yes",
5183 "&No",
5184 NULL,
5185 'y',
5186 'n',
5187 0,
5188 get_zc_font(font_lfont)) == 1)
5189 {
5190 zc_set_config("zeldadx","quest_dir","quests");
5191 flush_config_file();
5192 strcpy(qstdir,"quests");
5193 #ifdef __EMSCRIPTEN__
5194 em_sync_fs();
5195 #endif
5196 return D_O_K;
5197 }
5198 else return D_O_K;
5199 }
5200
5201
5202 int32_t onConsoleZASM()
5203 {
5204 if ( !zasm_debugger )
5205 {
5206 AlertDialog("WARNING: ZASM Debugger",
5207 "Enabling this will open the ZASM Debugger Console"
5208 "\nThis will likely grind ZC to a halt with lag."
5209 "\nTo make any use of this, it is suggested that you read"
5210 "\nthe documentation for 'void Breakpoint(char[] string);'"
5211 " in 'ZScript_Additions.txt'"
5212 "\nThis is not recommended for normal users,"
5213 " and is only intended for ZC developers,"
5214 "\nor quest developers coding directly in ZASM"
5215 "\nAre you sure that you wish to open the ZASM Debugger?",
5216 [&](bool ret,bool)
5217 {
5218 if(ret)
5219 {
5220 FFCore.ZASMPrint(true);
5221 }
5222 }).show();
5223 return D_O_K;
5224 }
5225 else
5226 {
5227 FFCore.ZASMPrint(false);
5228 return D_O_K;
5229 }
5230 }
5231
5232
5233 int32_t onConsoleZScript()
5234 {
5235 if ( !zscript_debugger )
5236 {
5237 AlertDialog("ZScript Debugger",
5238 "Enabling this will open the ZScript Debugger Console"
5239 "\nThis will display any messages logged by scripts,"
5240 " including script errors."
5241 "\nAre you sure that you wish to open the ZScript Debugger?",
5242 [&](bool ret,bool)
5243 {
5244 if(ret)
5245 {
5246 FFCore.ZScriptConsole(true);
5247 }
5248 }).show();
5249 return D_O_K;
5250 }
5251 else
5252 {
5253 FFCore.ZScriptConsole(false);
5254 return D_O_K;
5255 }
5256 }
5257
5258 int32_t onClrConsoleOnReload()
5259 {
5260 clearConsoleOnReload = !clearConsoleOnReload;
5261 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5262 return D_O_K;
5263 }
5264 int32_t onClrConsoleOnLoad()
5265 {
5266 clearConsoleOnLoad = !clearConsoleOnLoad;
5267 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5268 return D_O_K;
5269 }
5270
5271
5272 int32_t onFrameSkip()
5273 {
5274 FrameSkip = !FrameSkip;
5275 return D_O_K;
5276 }
5277
5278 int32_t onSaveDragResize()
5279 {
5280 SaveDragResize = !SaveDragResize;
5281 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5282 return D_O_K;
5283 }
5284
5285 int32_t onDragAspect()
5286 {
5287 DragAspect = !DragAspect;
5288 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5289 return D_O_K;
5290 }
5291
5292 int32_t onTransLayers()
5293 {
5294 TransLayers = !TransLayers;
5295 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5296 return D_O_K;
5297 }
5298
5299 int32_t onNESquit()
5300 {
5301 NESquit = !NESquit;
5302 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5303 return D_O_K;
5304 }
5305
5306 int32_t onVolKeys()
5307 {
5308 volkeys = !volkeys;
5309 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5310 return D_O_K;
5311 }
5312
5313 int32_t onShowFPS()
5314 {
5315 ShowFPS = !ShowFPS;
5316 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5317 return D_O_K;
5318 }
5319
5320 1095890898 bool is_Fkey(int32_t k)
5321 {
5322
2/2
✓ Branch 0 taken 111446532 times.
✓ Branch 1 taken 984444366 times.
1095890898 switch(k)
5323 {
5324 case KEY_F1:
5325 case KEY_F2:
5326 case KEY_F3:
5327 case KEY_F4:
5328 case KEY_F5:
5329 case KEY_F6:
5330 case KEY_F7:
5331 case KEY_F8:
5332 case KEY_F9:
5333 case KEY_F10:
5334 case KEY_F11:
5335 case KEY_F12:
5336 111446532 return true;
5337 }
5338
5339 984444366 return false;
5340 1095890898 }
5341
5342 void kb_getkey(DIALOG *d);
5343
5344 //Used by all keyboard key settings dialogues.
5345 void kb_clearjoystick(DIALOG *d)
5346 {
5347 d->flags|=D_SELECTED;
5348
5349 jwin_button_proc(MSG_DRAW,d,0);
5350 jwin_draw_win(gui_bmp, (gui_bmp->w-160)/2, (gui_bmp->h-48)/2, 168, 48, FR_WIN);
5351 // text_mode(vc(11));
5352 textout_centre_ex(gui_bmp, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5353 textout_centre_ex(gui_bmp, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5354
5355 update_hw_screen(true);
5356
5357 clear_keybuf();
5358 int32_t k = next_press_key();
5359 clear_keybuf();
5360
5361 //shnarf
5362 //47=f1
5363 //59=esc
5364 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5365 // *((int32_t*)d->dp3) = k;
5366 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5367
5368
5369 d->flags&=~D_SELECTED;
5370 }
5371
5372 //Clears key to 0.
5373 //Used by all keyboard key settings dialogues.
5374 void kb_clearkey(DIALOG *d);
5375
5376 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5377 {
5378 switch(msg)
5379 {
5380 case MSG_KEY:
5381 case MSG_CLICK:
5382
5383 kb_clearjoystick(d);
5384
5385 while(gui_mouse_b())
5386 {
5387 clear_keybuf();
5388 rest(1);
5389 }
5390
5391 return D_REDRAW;
5392 }
5393
5394 return jwin_button_proc(msg,d,c);
5395 }
5396
5397 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5398 //Only used in keyboard settings dialogues to clear keys.
5399 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5400
5401 int32_t j_getbtn(DIALOG *d)
5402 {
5403 d->flags|=D_SELECTED;
5404 jwin_button_proc(MSG_DRAW,d,0);
5405 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5406 // text_mode(vc(11));
5407 int32_t y = screen->h/2 - 12;
5408 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5409 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5410 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5411
5412 update_hw_screen(true);
5413
5414 int32_t b = next_joy_input(true);
5415 if (b == -2)
5416 return D_CLOSE;
5417
5418 if(b>=0)
5419 *((int32_t*)d->dp3) = b;
5420
5421 d->flags&=~D_SELECTED;
5422
5423 if (player)
5424 player->joy_on = TRUE;
5425
5426 return D_O_K;
5427 }
5428
5429 void j_getstick(DIALOG *d)
5430 {
5431 d->flags|=D_SELECTED;
5432 jwin_button_proc(MSG_DRAW,d,0);
5433 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5434 // text_mode(vc(11));
5435 int32_t y = screen->h/2 - 12;
5436 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5437 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5438 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5439
5440 update_hw_screen(true);
5441
5442 int32_t b = next_joy_input(false);
5443
5444 if(b>=0)
5445 *((int32_t*)d->dp3) = b;
5446
5447 d->flags&=~D_SELECTED;
5448
5449 if (player)
5450 player->joy_on = TRUE;
5451 }
5452
5453 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5454 {
5455 switch(msg)
5456 {
5457 case MSG_KEY:
5458 case MSG_CLICK:
5459
5460 int ret = j_getbtn(d);
5461 if (ret != D_O_K)
5462 return ret;
5463
5464 while(gui_mouse_b()) {
5465 rest(1);
5466 clear_keybuf();
5467 }
5468
5469 return D_REDRAW;
5470 }
5471
5472 return jwin_button_proc(msg,d,c);
5473 }
5474
5475 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5476 {
5477 switch(msg)
5478 {
5479 case MSG_KEY:
5480 case MSG_CLICK:
5481
5482 j_getstick(d);
5483
5484 while(gui_mouse_b()) {
5485 rest(1);
5486 clear_keybuf();
5487 }
5488
5489 return D_REDRAW;
5490 }
5491
5492 return jwin_button_proc(msg,d,c);
5493 }
5494
5495 //shnarf
5496 extern const char *key_str[];
5497 std::string get_keystr(int key);
5498
5499 const char *pan_str[4] = { "MONO", " 1/2", " 3/4", "FULL" };
5500 //extern int32_t zcmusic_bufsz;
5501
5502 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5503 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5504 str_primary_stick[80], str_secondary_stick[80];
5505
5506 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5507 {
5508 //these are here to bypass compiler warnings about unused arguments
5509 c=c;
5510
5511 if (d->w == 1)
5512 {
5513 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5514 {
5515 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5516 return D_CLOSE;
5517 }
5518 }
5519
5520 if(msg==MSG_DRAW)
5521 {
5522 switch(d->w)
5523 {
5524 case 0:
5525 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5526 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5527 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5528 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5529 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5530 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5531 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5532 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5533 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5534 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5535 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5536 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5537 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5538 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5539 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5540 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5541 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5542 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5543 break;
5544
5545 case 1:
5546 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5547 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5548 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5549 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5550 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5551 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5552 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5553 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5554 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5555 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5556 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5557 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5558 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5559 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5560 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5561 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5562 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5563 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5564 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5565 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5566 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5567 break;
5568
5569 case 2:
5570 sprintf(str_a," %3d",midi_volume);
5571 sprintf(str_b," %3d",digi_volume);
5572 sprintf(str_l," %3d",emusic_volume);
5573 sprintf(str_m," %3dKB",zcmusic_bufsz);
5574 sprintf(str_r," %3d",sfx_volume);
5575 strcpy(str_s,pan_str[pan_style]);
5576 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5577 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5578 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5579 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5580 break;
5581 }
5582 }
5583
5584 return D_O_K;
5585 }
5586
5587 int32_t set_vol(void *dp3, int32_t d2)
5588 {
5589 switch(((int32_t*)dp3)[0])
5590 {
5591 case 0:
5592 midi_volume = zc_min(d2<<3,255);
5593 break;
5594
5595 case 1:
5596 digi_volume = zc_min(d2<<3,255);
5597 break;
5598
5599 case 2:
5600 emusic_volume = zc_min(d2<<3,255);
5601 break;
5602
5603 case 3:
5604 sfx_volume = zc_min(d2<<3,255);
5605 break;
5606 }
5607
5608 // text_mode(vc(11));
5609 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%3d",zc_min(d2<<3,255));
5610 return D_O_K;
5611 }
5612
5613 int32_t set_pan(void *dp3, int32_t d2)
5614 {
5615 pan_style = vbound(d2,0,3);
5616 // text_mode(vc(11));
5617 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5618 return D_O_K;
5619 }
5620
5621 int32_t set_buf(void *dp3, int32_t d2)
5622 {
5623 // text_mode(vc(11));
5624 zcmusic_bufsz = d2 + 1;
5625 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%3dKB",zcmusic_bufsz);
5626 return D_O_K;
5627 }
5628
5629 static int32_t gamepad_joys_list[] =
5630 {
5631 61,
5632 -1
5633 };
5634
5635 static int32_t gamepad_btn_list[] =
5636 {
5637 6,
5638 7,8,9,10,11,12,13,14,15,16,17,
5639 18,19,20,21,22,23,24,25,26,27,28,
5640 29,30,31,32,33,34,35,36,37,38,39,
5641 -1
5642 };
5643
5644 static int32_t gamepad_dirs_list[] =
5645 {
5646 40,41,42,43,
5647 44,45,46,47,
5648 48,49,50,51,
5649 52,53,54,55,
5650 56,57,58,59,
5651 60,
5652 -1
5653 };
5654
5655 static TABPANEL gamepad_tabs[] =
5656 {
5657 // (text)
5658 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5659 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5660 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5661 { NULL, 0, NULL, 0, NULL }
5662 };
5663
5664 const char *joy_list(int32_t index, int32_t *list_size)
5665 {
5666 if (index == -1)
5667 {
5668 *list_size = al_get_num_joysticks();
5669 return NULL;
5670 }
5671
5672 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5673 if (!joy)
5674 {
5675 return "?";
5676 }
5677
5678 return al_get_joystick_name(joy);
5679 }
5680
5681 117 static ListData joy__list(joy_list, &font);
5682
5683 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5684 {
5685 int32_t d2 = d->d2;
5686 int32_t ret = jwin_droplist_proc(msg,d,c);
5687
5688 if(d2!=d->d2)
5689 {
5690 joystick_index = d->d2;
5691 ret |= D_REDRAW_ALL;
5692 }
5693
5694 return ret;
5695 }
5696
5697 static DIALOG gamepad_dlg[] =
5698 {
5699 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5700 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5701 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5702 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5703 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5704 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5705 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5706 // 6
5707 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5708 // 7
5709 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5710 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5711 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5712 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5713 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5714 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5715 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5716 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5717 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5718 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5719 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5720 // 18
5721 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5722 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5723 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5724 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5725 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5726 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5727 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5728 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5729 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5730 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5731 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5732 // 29
5733 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5734 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5735 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5736 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5737 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5738 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5739 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5740 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5741 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5742 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5743 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5744 // 40
5745 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5746 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5747 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5748 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5749 // 44
5750 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5751 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5752 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5753 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5754 // 48
5755 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5756 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5757 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5758 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5759 // 52
5760 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5761 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5762 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5763 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5764 // 56
5765 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5766 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5767 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5768 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5769 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5770
5771 // 61
5772 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5773
5774 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5775 };
5776
5777 static int32_t keyboard_keys_list[] =
5778 {
5779 6,7,8,9,10,
5780 11,12,13,14,15,16,17,18,19,20,
5781 21,22,23,24,25,26,27,28,29,30,
5782 31,32,33,34,35,36,37,38,39,40,
5783 -1
5784 };
5785
5786 static int32_t keyboard_dirs_list[] =
5787 {
5788 41,42,43,44,
5789 45,46,47,48,
5790 49,50,51,52,
5791 53,54,55,56,
5792 -1
5793 };
5794
5795 static int32_t keyboard_mods_list[] =
5796 {
5797 57,58,59,60,
5798 61,62,63,64,
5799 65,66,67,68,
5800 69,70,71,72,
5801 -1
5802 };
5803
5804 static TABPANEL keyboard_control_tabs[] =
5805 {
5806 // (text)
5807 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5808 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5809 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5810 { NULL, 0, NULL, 0, NULL }
5811 };
5812
5813 static DIALOG keyboard_control_dlg[] =
5814 {
5815 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5816 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5817 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5818 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5819 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5820 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5821 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5822 // Keys
5823 // 6
5824 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5825 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5826 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5827 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5828 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5829 // 11
5830 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5831 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5832 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5833 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5834 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5835 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5836 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5837 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5838 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5839 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5840 // 21
5841 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5842 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5843 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5844 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5845 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5846 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5847 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5848 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5849 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5850 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5851 // 31
5852 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5853 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5854 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5855 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5856 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5857 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5858 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5859 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5860 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5861 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5862 // Dirs
5863 // 41
5864 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5865 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5866 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5867 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5868 // 45
5869 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5870 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5871 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5872 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5873 // 49
5874 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5875 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5876 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5877 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5878 // 53
5879 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5880 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5881 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5882 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5883 // Mods
5884 // 57
5885 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5886 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5887 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5888 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5889 // 61
5890 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5891 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5892 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5893 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5894 // 65
5895 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5896 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5897 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5898 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5899 // 69
5900 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5901 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5902 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5903 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5904 // 73
5905 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5906 };
5907
5908 /*
5909 int32_t midi_dp[3] = {0,147,104};
5910 int32_t digi_dp[3] = {1,147,120};
5911 int32_t pan_dp[3] = {0,147,136};
5912 int32_t buf_dp[3] = {0,147,152};
5913 */
5914 int32_t midi_dp[3] = {0,0,0};
5915 int32_t digi_dp[3] = {1,0,0};
5916 int32_t emus_dp[3] = {2,0,0};
5917 int32_t buf_dp[3] = {0,0,0};
5918 int32_t sfx_dp[3] = {3,0,0};
5919 int32_t pan_dp[3] = {0,0,0};
5920
5921 static DIALOG sound_dlg[] =
5922 {
5923 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5924 117 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5925 117 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5926 117 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5927 117 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5928 117 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5929 117 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5930 117 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5931 117 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_b, NULL, NULL },
5932 117 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5933 117 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_m, NULL, NULL },
5934 // 10
5935 117 { jwin_rtext_proc, 190, 104, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5936 117 { jwin_rtext_proc, 190, 120, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5937 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5938 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5939 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5940 117 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5941 117 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, digi_dp },
5942 117 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5943 117 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 127, 0, NULL, (void *) set_buf, buf_dp },
5944 117 { jwin_slider_proc, 196, 104, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5945 //20
5946 117 { jwin_slider_proc, 196, 120, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5947 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5948 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5949 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5950 117 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Master MIDI Volume", NULL, NULL },
5951 117 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Master Digi Volume", NULL, NULL },
5952 117 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Enhanced Music Volume", NULL, NULL },
5953 117 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Enhanced Music Buffer", NULL, NULL },
5954 117 { jwin_text_proc, 17, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5955 117 { jwin_text_proc, 17, 120, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5956 //30
5957 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5958 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5959 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5960 117 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5961 };
5962
5963 char zc_builddate[80];
5964 char zc_aboutstr[80];
5965
5966 static DIALOG about_dlg[] =
5967 {
5968 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5969 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5970 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5971 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5972 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5973 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5974 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5975 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5976 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5977 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5978 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5979 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5980 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5981 };
5982
5983
5984 static DIALOG quest_dlg[] =
5985 {
5986 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5987 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5988 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5989 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5990 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5991 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5992 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5993 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5994 { jwin_text_proc, 130, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5995 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
5996 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
5997 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
5998 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
5999 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
6000 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6001 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6002 };
6003
6004 static DIALOG triforce_dlg[] =
6005 {
6006 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6007 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
6008 // 1
6009 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
6010 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
6011 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
6012 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
6013 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
6014 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
6015 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
6016 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
6017 // 9
6018 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6019 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6020 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6021 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6022 };
6023
6024 bool zc_getname(const char *prompt,const char *ext,EXT_LIST *list,const char *def,bool usefilename)
6025 {
6026 go();
6027 int32_t ret=0;
6028 ret = zc_getname_nogo(prompt,ext,list,def,usefilename);
6029 comeback();
6030 return ret != 0;
6031 }
6032
6033
6034 bool zc_getname_nogo(const char *prompt,const char *ext,EXT_LIST *list,const char *def,bool usefilename)
6035 {
6036 if(def!=modulepath)
6037 strcpy(modulepath,def);
6038
6039 if(!usefilename)
6040 {
6041 int32_t i=(int32_t)strlen(modulepath);
6042
6043 while(i>=0 && modulepath[i]!='\\' && modulepath[i]!='/')
6044 modulepath[i--]=0;
6045 }
6046
6047 // int32_t ret = file_select_ex(prompt,modulepath,ext,255,-1,-1);
6048 int32_t ret=0;
6049 int32_t sel=0;
6050
6051 if(list==NULL)
6052 {
6053 ret = jwin_file_select_ex(prompt,modulepath,ext,2048,-1,-1,get_zc_font(font_lfont));
6054 }
6055 else
6056 {
6057 ret = jwin_file_browse_ex(prompt, modulepath, list, &sel, 2048, -1, -1, get_zc_font(font_lfont));
6058 }
6059
6060 return ret!=0;
6061 }
6062
6063 int32_t onToggleRecordingNewSaves()
6064 {
6065 if (zc_get_config("zeldadx", "replay_new_saves", false))
6066 {
6067 zc_set_config("zeldadx", "replay_new_saves", false);
6068 }
6069 else
6070 {
6071 zc_set_config("zeldadx", "replay_new_saves", true);
6072 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
6073 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6074 }
6075 return D_O_K;
6076 }
6077
6078 int32_t onToggleSnapshotAllFrames()
6079 {
6080 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
6081 return D_O_K;
6082 }
6083
6084 int32_t onStopReplayOrRecord()
6085 {
6086 if (replay_is_replaying())
6087 {
6088 replay_quit();
6089 }
6090 else if (replay_get_mode() == ReplayMode::Record)
6091 {
6092 if (!replay_get_meta_bool("test_mode"))
6093 {
6094 jwin_alert("Recording", "You cannot stop recording a save file.",
6095 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6096 return D_CLOSE;
6097 }
6098
6099 if (jwin_alert("Stop Recording",
6100 "Save replay to disk and stop recording?",
6101 "This will stop the recording.",
6102 NULL,
6103 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
6104 return D_CLOSE;
6105
6106 replay_save();
6107 replay_stop();
6108 }
6109 return D_O_K;
6110 }
6111
6112 static int32_t handle_on_load_replay(ReplayMode mode)
6113 {
6114 if (Playing)
6115 {
6116 if (jwin_alert("Replay - Warning!",
6117 "Loading a replay will exit the current game.",
6118 "All unsaved progress will be lost.",
6119 "Do you wish to continue?",
6120 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
6121 return D_CLOSE;
6122 }
6123
6124 std::string mode_string = replay_mode_to_string(mode);
6125 mode_string[0] = std::toupper(mode_string[0]);
6126
6127 std::string line_1 = "Select a replay file to play back.";
6128 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
6129 std::string line_3 = "You can stop the replay and take over manually any time.";
6130 if (mode == ReplayMode::Update)
6131 {
6132 line_1 = "Select a replay file to update.";
6133 line_2 = "WARNING: be sure to back up the zplay file";
6134 line_3 = "and verify that the updated replay works as expected!";
6135 }
6136
6137 if (jwin_alert(mode_string.c_str(),
6138 line_1.c_str(),
6139 line_2.c_str(),
6140 line_3.c_str(),
6141 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
6142 {
6143 char replay_path[2048];
6144 strcpy(replay_path, "replays/");
6145 if (jwin_file_select_ex(
6146 fmt::format("Load Replay ({})", REPLAY_EXTENSION).c_str(),
6147 replay_path, REPLAY_EXTENSION.c_str(), 2048, -1, -1, get_zc_font(font_lfont)) == 0)
6148 return D_CLOSE;
6149
6150 replay_quit();
6151 load_replay_file_deferred(mode, replay_path);
6152 Quit = qRESET;
6153 return D_CLOSE;
6154 }
6155 return D_O_K;
6156 }
6157
6158 int32_t onLoadReplay()
6159 {
6160 return handle_on_load_replay(ReplayMode::Replay);
6161 }
6162
6163 int32_t onLoadReplayAssert()
6164 {
6165 return handle_on_load_replay(ReplayMode::Assert);
6166 }
6167
6168 int32_t onLoadReplayUpdate()
6169 {
6170 return handle_on_load_replay(ReplayMode::Update);
6171 }
6172
6173 int32_t onSaveReplay()
6174 {
6175 if (replay_get_mode() == ReplayMode::Record)
6176 {
6177 if (!replay_get_meta_bool("test_mode"))
6178 {
6179 if (jwin_alert("Save Replay",
6180 "This will save a copy of the replay up to this point.",
6181 "The official replay file will be untouched.",
6182 "Do you wish to continue?",
6183 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
6184 return D_CLOSE;
6185
6186 char replay_path[2048];
6187 strcpy(replay_path, replay_get_replay_path().string().c_str());
6188 if (jwin_file_select_ex(
6189 fmt::format("Save Replay ({})", REPLAY_EXTENSION).c_str(),
6190 replay_path, REPLAY_EXTENSION.c_str(), 2048, -1, -1, get_zc_font(font_lfont)) == 0)
6191 return D_CLOSE;
6192
6193 if (fileexists(replay_path))
6194 {
6195 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
6196 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6197 return D_CLOSE;
6198 }
6199
6200 replay_save(replay_path);
6201 }
6202 else
6203 {
6204 replay_save();
6205 }
6206 }
6207 return D_O_K;
6208 }
6209
6210 static MENU replay_menu[] =
6211 {
6212 { (char *)"Record new saves", onToggleRecordingNewSaves, NULL, 0, NULL },
6213 { (char *)"Stop replay", onStopReplayOrRecord, NULL, 0, NULL },
6214 { (char *)"Load replay", onLoadReplay, NULL, 0, NULL },
6215 { (char *)"Load replay (assert)", onLoadReplayAssert, NULL, 0, NULL },
6216 { (char *)"Load replay (update)", onLoadReplayUpdate, NULL, 0, NULL },
6217 { (char *)"Save replay", onSaveReplay, NULL, 0, NULL },
6218 { (char *)"Enable snapshot all frames", onToggleSnapshotAllFrames,NULL, 0, NULL },
6219
6220 { NULL, NULL, NULL, 0, NULL }
6221 };
6222
6223 static DIALOG credits_dlg[] =
6224 {
6225 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6226 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
6227 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
6228 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6229 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6230 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6231 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6232 };
6233
6234 117 static ListData dmap_list(dmaplist, &font);
6235
6236 static DIALOG goto_dlg[] =
6237 {
6238 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6239 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6240 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6241 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6242 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6243 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6244 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6245 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6246 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6247 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6248 };
6249
6250 int32_t onGoTo()
6251 {
6252 bool music = false;
6253 music = music;
6254 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6255
6256 goto_dlg[0].dp2=get_zc_font(font_lfont);
6257 goto_dlg[4].d2=cheat_goto_dmap;
6258 goto_dlg[6].dp=cheat_goto_screen_str;
6259
6260 clear_keybuf();
6261
6262 large_dialog(goto_dlg);
6263
6264 if(do_zqdialog(goto_dlg,4)==1)
6265 {
6266 // dmap, screen
6267 cheats_enqueue(Cheat::GoTo, goto_dlg[4].d2, zc_min(zc_xtoi(cheat_goto_screen_str),0x7F));
6268 };
6269
6270 return D_O_K;
6271 }
6272
6273 int32_t onGoToComplete()
6274 {
6275 if(!Playing)
6276 {
6277 return D_O_K;
6278 }
6279
6280 enter_sys_pal();
6281 music_pause();
6282 pause_all_sfx();
6283 onGoTo();
6284 eat_buttons();
6285
6286 zc_readrawkey(KEY_ESC);
6287
6288 exit_sys_pal();
6289 music_resume();
6290 resume_all_sfx();
6291 return D_O_K;
6292 }
6293
6294 int32_t onCredits()
6295 {
6296 return D_O_K;
6297 }
6298
6299 const char *midilist(int32_t index, int32_t *list_size)
6300 {
6301 if(index<0)
6302 {
6303 *list_size=0;
6304
6305 for(int32_t i=0; i<MAXMIDIS; i++)
6306 if(tunes[i].data)
6307 ++(*list_size);
6308
6309 return NULL;
6310 }
6311
6312 int32_t i=0,m=0;
6313
6314 while(m<=index && i<=MAXMIDIS)
6315 {
6316 if(tunes[i].data)
6317 ++m;
6318
6319 ++i;
6320 }
6321
6322 --i;
6323
6324 if(i==MAXMIDIS && m<index)
6325 return "(null)";
6326
6327 return tunes[i].title;
6328 }
6329
6330 /* ------- MIDI info stuff -------- */
6331
6332 char *text;
6333 midi_info *zmi;
6334 bool dialog_running;
6335 bool listening;
6336
6337 void get_info(int32_t index);
6338
6339 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6340 {
6341 int32_t d2 = d->d2;
6342 int32_t ret = jwin_droplist_proc(msg,d,c);
6343
6344 if(d2!=d->d2)
6345 {
6346 get_info(d->d2);
6347 }
6348
6349 return ret;
6350 }
6351
6352 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6353 {
6354 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6355
6356 int32_t ret = jwin_button_proc(msg,d,c);
6357
6358 if(ret == D_CLOSE)
6359 {
6360 // get current midi index
6361 int32_t index = (d+(d->d1))->d2;
6362 int32_t i=0, m=0;
6363
6364 while(m<=index && i<=MAXMIDIS)
6365 {
6366 if(tunes[i].data)
6367 ++m;
6368
6369 ++i;
6370 }
6371
6372 --i;
6373 jukebox(i);
6374 listening = true;
6375 ret = D_O_K;
6376 }
6377
6378 return ret;
6379 }
6380
6381 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6382 {
6383 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6384
6385 int32_t ret = jwin_button_proc(msg,d,c);
6386
6387 if(ret == D_CLOSE)
6388 {
6389 // get current midi index
6390 int32_t index = (d+(d->d1))->d2;
6391 int32_t i=0, m=0;
6392
6393 while(m<=index && i<=MAXMIDIS)
6394 {
6395 if(tunes[i].data)
6396 ++m;
6397
6398 ++i;
6399 }
6400
6401 --i;
6402
6403 // get file name
6404
6405 int32_t sel=0;
6406 //struct ffblk f;
6407 char title[40] = "Save MIDI: ";
6408 char fname[2048];
6409 memset(fname,0,2048);
6410 static EXT_LIST list[] =
6411 {
6412 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6413 { (char *)"HTML files (*.html, *.html)", (char *)"htm html" },
6414 { NULL, NULL }
6415 };
6416
6417 strcpy(title+11, tunes[i].title);
6418 title[39] = '\0';
6419
6420 if(jwin_file_browse_ex(title, fname, list, &sel, 2048, -1, -1, get_zc_font(font_lfont))==0)
6421 goto done;
6422
6423 if(exists(fname))
6424 {
6425 if(jwin_alert(title, fname, "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6426 goto done;
6427 }
6428
6429 // save midi i
6430
6431 if(save_midi(fname, (MIDI*)tunes[i].data) != 0)
6432 jwin_alert(title, "Error saving MIDI to", fname, NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6433
6434 done:
6435 chop_path(fname);
6436 ret = D_REDRAW;
6437 }
6438
6439 return ret;
6440 }
6441
6442 117 static ListData midi_list(midilist, &font);
6443
6444 static DIALOG midi_dlg[] =
6445 {
6446 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6447 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6448 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6449 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6450 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6451 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6452 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6453 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6454 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6455 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6456 };
6457
6458 void get_info(int32_t index)
6459 {
6460 int32_t i=0, m=0;
6461
6462 while(m<=index && i<=MAXMIDIS)
6463 {
6464 if(tunes[i].data)
6465 ++m;
6466
6467 ++i;
6468 }
6469
6470 --i;
6471
6472 if(i==MAXMIDIS && m<index)
6473 strcpy(text,"(null)");
6474 else
6475 {
6476 get_midi_info((MIDI*)tunes[i].data,zmi);
6477 get_midi_text((MIDI*)tunes[i].data,zmi,text);
6478 }
6479
6480 midi_dlg[0].dp2=get_zc_font(font_lfont);
6481 midi_dlg[3].dp = text;
6482 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6483 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6484
6485 if(dialog_running)
6486 {
6487 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6488 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6489 }
6490 }
6491
6492 int32_t onMIDICredits()
6493 {
6494 text = (char*)malloc(4096);
6495 zmi = (midi_info*)malloc(sizeof(midi_info));
6496
6497 if(!text || !zmi)
6498 {
6499 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6500 return D_O_K;
6501 }
6502
6503 bool do_pause_midi = midi_pos >= 0 && currmidi;
6504 auto restore_midi = currmidi;
6505 if(do_pause_midi)
6506 {
6507 paused_midi_pos = midi_pos;
6508 stop_midi();
6509 midi_suspended = midissuspHALTED;
6510 }
6511
6512 midi_dlg[0].dp2=get_zc_font(font_lfont);
6513 midi_dlg[2].d1 = 0;
6514 midi_dlg[2].d2 = 0;
6515 midi_dlg[4].flags = D_EXIT;
6516 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6517
6518 listening = false;
6519 dialog_running=false;
6520 get_info(0);
6521
6522 dialog_running=true;
6523
6524 large_dialog(midi_dlg);
6525
6526 do_zqdialog(midi_dlg,0);
6527 dialog_running=false;
6528
6529 if(listening)
6530 music_stop();
6531
6532 if(do_pause_midi)
6533 {
6534 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6535 midi_suspended = midissuspRESUME;
6536 currmidi = restore_midi;
6537 midi_pos = paused_midi_pos;
6538 }
6539
6540 if(text) free(text);
6541 if(zmi) free(zmi);
6542 return D_O_K;
6543 }
6544
6545 int32_t onAbout()
6546 {
6547 char buf1[80]={0};
6548 std::ostringstream oss;
6549 sprintf(buf1,ZC_PLAYER_NAME);
6550 oss << buf1 << '\n';
6551 sprintf(buf1,"Version: %s", getVersionString());
6552 oss << buf1 << '\n';
6553 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6554 oss << buf1 << '\n';
6555 sprintf(buf1, "Built By: %s", DEV_SIGNOFF);
6556 oss << buf1 << '\n';
6557
6558 InfoDialog("About ZC", oss.str()).show();
6559 return D_O_K;
6560 }
6561
6562 int32_t onQuest()
6563 {
6564 char fname[100];
6565 strcpy(fname, get_filename(qstpath));
6566 quest_dlg[0].dp2=get_zc_font(font_lfont);
6567 quest_dlg[1].dp = fname;
6568
6569 if(QHeader.quest_number==0)
6570 sprintf(str_a,"Custom");
6571 else
6572 sprintf(str_a,"%d",QHeader.quest_number);
6573
6574 sprintf(str_s,"%s",QHeader.getVerStr());
6575
6576 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6577 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6578
6579 large_dialog(quest_dlg);
6580
6581 do_zqdialog(quest_dlg, 0);
6582 return D_O_K;
6583 }
6584
6585 void call_vidmode_dlg();
6586 int32_t onVidMode()
6587 {
6588 call_vidmode_dlg();
6589 return D_O_K;
6590 }
6591
6592 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6593 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6594 //Added an extra statement, so that if the key is cleared to 0, the cleared
6595 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6596
6597 void load_ukeys(int32_t* arr)
6598 {
6599 arr[ukey_a] = Akey;
6600 arr[ukey_b] = Bkey;
6601 arr[ukey_s] = Skey;
6602 arr[ukey_l] = Lkey;
6603 arr[ukey_r] = Rkey;
6604 arr[ukey_p] = Pkey;
6605 arr[ukey_ex1] = Exkey1;
6606 arr[ukey_ex2] = Exkey2;
6607 arr[ukey_ex3] = Exkey3;
6608 arr[ukey_ex4] = Exkey4;
6609 arr[ukey_du] = DUkey;
6610 arr[ukey_dd] = DDkey;
6611 arr[ukey_dl] = DLkey;
6612 arr[ukey_dr] = DRkey;
6613 arr[ukey_mod1a] = cheat_modifier_keys[0];
6614 arr[ukey_mod1b] = cheat_modifier_keys[1];
6615 arr[ukey_mod2a] = cheat_modifier_keys[2];
6616 arr[ukey_mod2b] = cheat_modifier_keys[3];
6617 };
6618
6619 static const char* ukey_names[] = {
6620 "A", "B", "Start", "L", "R", "Map",
6621 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6622 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6623 "Cheat Mod R1", "Cheat Mod R2",
6624 };
6625 std::string get_ukey_name(int32_t k)
6626 {
6627 if (k < num_ukey) return ukey_names[k];
6628 return "";
6629 }
6630
6631 int32_t onKeyboard()
6632 {
6633 int32_t a = Akey;
6634 int32_t b = Bkey;
6635 int32_t s = Skey;
6636 int32_t l = Lkey;
6637 int32_t r = Rkey;
6638 int32_t p = Pkey;
6639 int32_t ex1 = Exkey1;
6640 int32_t ex2 = Exkey2;
6641 int32_t ex3 = Exkey3;
6642 int32_t ex4 = Exkey4;
6643 int32_t du = DUkey;
6644 int32_t dd = DDkey;
6645 int32_t dl = DLkey;
6646 int32_t dr = DRkey;
6647 int32_t mod1a = cheat_modifier_keys[0];
6648 int32_t mod1b = cheat_modifier_keys[1];
6649 int32_t mod2a = cheat_modifier_keys[2];
6650 int32_t mod2b = cheat_modifier_keys[3];
6651 bool done=false;
6652 int32_t ret;
6653
6654 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6655
6656 large_dialog(keyboard_control_dlg);
6657
6658 while(!done)
6659 {
6660 ret = do_zqdialog(keyboard_control_dlg,3);
6661
6662 if(ret==3) // OK
6663 {
6664 int32_t ukeys[num_ukey];
6665 load_ukeys(ukeys);
6666 std::vector<std::string> uniqueError;
6667 for(int32_t q = 0; q < num_ukey; ++q)
6668 {
6669 for(int32_t p = q+1; p < num_ukey; ++p)
6670 {
6671 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6672 {
6673 char buf[64];
6674 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6675 std::string str(buf);
6676 uniqueError.push_back(str);
6677 }
6678 }
6679 }
6680 if(uniqueError.size() == 0)
6681 {
6682 done = true;
6683 save_control_configs(true);
6684 }
6685 else
6686 {
6687 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6688 box_out("Cannot have duplicate keybinds!"); box_eol();
6689 for(std::vector<std::string>::iterator it = uniqueError.begin();
6690 it != uniqueError.end(); ++it)
6691 {
6692 box_out((*it).c_str()); box_eol();
6693 }
6694 box_end(true);
6695 }
6696 }
6697 else // Cancel
6698 {
6699 Akey = a;
6700 Bkey = b;
6701 Skey = s;
6702 Lkey = l;
6703 Rkey = r;
6704 Pkey = p;
6705 Exkey1 = ex1;
6706 Exkey2 = ex2;
6707 Exkey3 = ex3;
6708 Exkey4 = ex4;
6709 DUkey = du;
6710 DDkey = dd;
6711 DLkey = dl;
6712 DRkey = dr;
6713 cheat_modifier_keys[0] = mod1a;
6714 cheat_modifier_keys[1] = mod1b;
6715 cheat_modifier_keys[2] = mod2a;
6716 cheat_modifier_keys[3] = mod2b;
6717
6718 done=true;
6719 }
6720
6721 rest(1);
6722 }
6723
6724 return D_O_K;
6725 }
6726
6727 int32_t onGamepad()
6728 {
6729 if (al_get_num_joysticks() == 0)
6730 {
6731 InfoDialog("ZC", "No gamepads detected.").show();
6732 return D_O_K;
6733 }
6734
6735 int32_t a = Abtn;
6736 int32_t b = Bbtn;
6737 int32_t s = Sbtn;
6738 int32_t l = Lbtn;
6739 int32_t r = Rbtn;
6740 int32_t m = Mbtn;
6741 int32_t p = Pbtn;
6742 int32_t ex1 = Exbtn1;
6743 int32_t ex2 = Exbtn2;
6744 int32_t ex3 = Exbtn3;
6745 int32_t ex4 = Exbtn4;
6746 int32_t up = DUbtn;
6747 int32_t down = DDbtn;
6748 int32_t left = DLbtn;
6749 int32_t right = DRbtn;
6750 int32_t joy = joystick_index;
6751 int32_t stick_1 = js_stick_1_x_stick;
6752 int32_t stick_2 = js_stick_2_x_stick;
6753
6754 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6755 if(analog_movement)
6756 gamepad_dlg[56].flags|=D_SELECTED;
6757 else
6758 gamepad_dlg[56].flags&=~D_SELECTED;
6759
6760 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6761 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6762 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6763 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6764 // requires remapping every time.
6765 if (joystick_index >= al_get_num_joysticks())
6766 joystick_index = 0;
6767 gamepad_dlg[61].d2 = joystick_index;
6768
6769 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6770 if (!gamepad_dlg_cur_joystick)
6771 {
6772 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6773 return D_CLOSE;
6774 }
6775
6776 large_dialog(gamepad_dlg);
6777
6778 int32_t ret = do_zqdialog(gamepad_dlg,4);
6779
6780 if(ret == 4) //OK
6781 {
6782 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6783 joystick_index = gamepad_dlg[61].d2;
6784 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6785 if (!gamepad_dlg_cur_joystick)
6786 {
6787 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6788 return D_CLOSE;
6789 }
6790 js_stick_1_y_stick = js_stick_1_x_stick;
6791 js_stick_2_y_stick = js_stick_2_x_stick;
6792 save_control_configs(false);
6793 }
6794 else //Cancel
6795 {
6796 Abtn = a;
6797 Bbtn = b;
6798 Sbtn = s;
6799 Lbtn = l;
6800 Rbtn = r;
6801 Mbtn = m;
6802 Pbtn = p;
6803 Exbtn1 = ex1;
6804 Exbtn2 = ex2;
6805 Exbtn3 = ex3;
6806 Exbtn4 = ex4;
6807 DUbtn = up;
6808 DDbtn = down;
6809 DLbtn = left;
6810 DRbtn = right;
6811 joystick_index = joy;
6812 js_stick_1_x_stick = stick_1;
6813 js_stick_2_x_stick = stick_2;
6814 }
6815
6816 return D_O_K;
6817 }
6818
6819 int32_t onCheatKeys()
6820 {
6821 int32_t oldcheats[Cheat::Last][2];
6822 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6823
6824 bool done=false;
6825
6826 while(!done)
6827 {
6828 bool confirm = false;
6829 CheatKeysDialog(&confirm).show();
6830 if(confirm) // OK
6831 {
6832 std::vector<std::string> uniqueError;
6833 char buf[512];
6834 for(size_t q = 1; q < Cheat::Last; ++q)
6835 {
6836 if(cheatkeys[q][1] && !cheatkeys[q][0])
6837 {
6838 cheatkeys[q][0] = cheatkeys[q][1];
6839 cheatkeys[q][1] = 0;
6840 }
6841 }
6842 for(size_t q = 1; q < Cheat::Last; ++q)
6843 {
6844 if(!bindable_cheat((Cheat)q)) continue;
6845 for(size_t p = q+1; p < Cheat::Last; ++p)
6846 {
6847 if(!bindable_cheat((Cheat)p)) continue;
6848 for(size_t q2 = 0; q2 <= 1; ++q2)
6849 for(size_t p2 = 0; p2 <= 1; ++p2)
6850 {
6851 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6852 {
6853 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6854 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6855 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6856 get_keystr(cheatkeys[q][q2])));
6857 }
6858 }
6859 }
6860 }
6861 if(uniqueError.size() == 0)
6862 {
6863 done = true;
6864 save_cheatkeys();
6865 }
6866 else
6867 {
6868 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6869 box_out("Cannot have duplicate keybinds!"); box_eol();
6870 for(std::vector<std::string>::iterator it = uniqueError.begin();
6871 it != uniqueError.end(); ++it)
6872 {
6873 box_out((*it).c_str()); box_eol();
6874 }
6875 box_end(true);
6876 }
6877 }
6878 else // Cancel
6879 {
6880 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6881 done=true;
6882 }
6883 rest(1);
6884 }
6885
6886 return D_O_K;
6887 }
6888
6889 int32_t onSound()
6890 {
6891 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6892 {
6893 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6894 {
6895 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6896 }
6897 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6898 {
6899 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6900 }
6901 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6902 {
6903 emusic_volume = (int32_t)FFCore.usr_music_volume;
6904 }
6905 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6906 {
6907 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6908 }
6909 }
6910 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6911 {
6912 pan_style = (int32_t)FFCore.usr_panstyle;
6913 }
6914
6915 int32_t m = midi_volume;
6916 int32_t d = digi_volume;
6917 int32_t e = emusic_volume;
6918 int32_t b = zcmusic_bufsz;
6919 int32_t s = sfx_volume;
6920 int32_t p = pan_style;
6921 pan_style = vbound(pan_style,0,3);
6922
6923 sound_dlg[0].dp2=get_zc_font(font_lfont);
6924
6925 large_dialog(sound_dlg);
6926
6927 midi_dp[1] = sound_dlg[6].x;
6928 midi_dp[2] = sound_dlg[6].y;
6929 digi_dp[1] = sound_dlg[7].x;
6930 digi_dp[2] = sound_dlg[7].y;
6931 emus_dp[1] = sound_dlg[8].x;
6932 emus_dp[2] = sound_dlg[8].y;
6933 buf_dp[1] = sound_dlg[9].x;
6934 buf_dp[2] = sound_dlg[9].y;
6935 sfx_dp[1] = sound_dlg[10].x;
6936 sfx_dp[2] = sound_dlg[10].y;
6937 pan_dp[1] = sound_dlg[11].x;
6938 pan_dp[2] = sound_dlg[11].y;
6939 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6940 sound_dlg[16].d2 = (digi_volume==255) ? 32 : digi_volume>>3;
6941 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6942 sound_dlg[18].d2 = zcmusic_bufsz;
6943 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6944 sound_dlg[20].d2 = pan_style;
6945
6946 int32_t ret = do_zqdialog(sound_dlg,1);
6947
6948 if(ret==2)
6949 {
6950 master_volume(digi_volume,midi_volume);
6951 if (zcmusic)
6952 zcmusic_set_volume(zcmusic, emusic_volume);
6953
6954 int32_t temp_volume = sfx_volume;
6955 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6956 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6957 for(int32_t i=0; i<WAV_COUNT; ++i)
6958 {
6959 //allegro assertion fails when passing in -1 as voice -DD
6960 if(sfx_voice[i] > 0)
6961 voice_set_volume(sfx_voice[i], temp_volume);
6962 }
6963 zc_set_config(sfx_sect,"digi",digi_volume);
6964 zc_set_config(sfx_sect,"midi",midi_volume);
6965 zc_set_config(sfx_sect,"sfx",sfx_volume);
6966 zc_set_config(sfx_sect,"emusic",emusic_volume);
6967 zc_set_config(sfx_sect,"pan",pan_style);
6968 zc_set_config(sfx_sect,"zcmusic_bufsz",zcmusic_bufsz);
6969 }
6970 else
6971 {
6972 midi_volume = m;
6973 digi_volume = d;
6974 emusic_volume = e;
6975 zcmusic_bufsz = b;
6976 sfx_volume = s;
6977 pan_style = p;
6978 }
6979
6980 return D_O_K;
6981 }
6982
6983 int32_t queding(char const* s1, char const* s2, char const* s3)
6984 {
6985 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6986 }
6987
6988 int32_t onQuit()
6989 {
6990 if(Playing)
6991 {
6992 int32_t ret=0;
6993
6994 if(get_qr(qr_NOCONTINUE))
6995 {
6996 if(standalone_mode)
6997 {
6998 ret=queding("End current game?",
6999 "The continue screen is disabled; the game",
7000 "will be reloaded from the last save.");
7001 }
7002 else
7003 {
7004 ret=queding("End current game?",
7005 "The continue screen is disabled. You will",
7006 "be returned to the file select screen.");
7007 }
7008 }
7009 else
7010 ret=queding("End current game?",NULL,NULL);
7011
7012 if(ret==1)
7013 {
7014 disableClickToFreeze=false;
7015 Quit=qQUIT;
7016
7017 // Trying to evade a door repair charge?
7018 if(repaircharge)
7019 {
7020 game->change_drupy(-repaircharge);
7021 repaircharge=0;
7022 }
7023
7024 return D_CLOSE;
7025 }
7026 }
7027
7028 return D_O_K;
7029 }
7030
7031 int32_t onTryQuitMenu()
7032 {
7033 return onTryQuit(true);
7034 }
7035
7036 int32_t onTryQuit(bool inMenu)
7037 {
7038 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
7039 {
7040 if(active_cutscene.can_f6())
7041 {
7042 if(get_qr(qr_OLD_F6))
7043 {
7044 if(inMenu) onQuit();
7045 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
7046 }
7047 else
7048 {
7049 disableClickToFreeze=false;
7050 GameFlags |= GAMEFLAG_TRYQUIT;
7051 }
7052 return D_CLOSE;
7053 }
7054 else active_cutscene.error();
7055 }
7056
7057 return D_O_K;
7058 }
7059
7060 int32_t onReset()
7061 {
7062 if(queding(" Reset system? ",NULL,NULL)==1)
7063 {
7064 disableClickToFreeze=false;
7065 Quit=qRESET;
7066 replay_quit();
7067 return D_CLOSE;
7068 }
7069
7070 return D_O_K;
7071 }
7072
7073 int32_t onExit()
7074 {
7075 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
7076 {
7077 Quit=qEXIT;
7078 return D_CLOSE;
7079 }
7080
7081 return D_O_K;
7082 }
7083
7084 int32_t onDebug()
7085 {
7086 if(debug_enabled)
7087 set_debug(!get_debug());
7088 return D_O_K;
7089 }
7090
7091 int32_t onHeartBeep()
7092 {
7093 heart_beep=!heart_beep;
7094 zc_set_config(cfg_sect,"heart_beep",heart_beep);
7095 return D_O_K;
7096 }
7097
7098 int32_t onSaveIndicator()
7099 {
7100 use_save_indicator = use_save_indicator ? 0 : 1;
7101 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
7102 return D_O_K;
7103 }
7104
7105 int32_t onEpilepsy()
7106 {
7107 if(jwin_alert3(
7108 "Epilepsy Flash Reduction",
7109 "Enabling this will reduce the intensity of flashing and screen wave effects.",
7110 "Disabling this will restore standard flash and wavy behaviour.",
7111 "Proceed?",
7112 "&Yes",
7113 "&No",
7114 NULL,
7115 'y',
7116 'n',
7117 0,
7118 get_zc_font(font_lfont)) == 1)
7119 {
7120 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
7121 zc_set_config("zeldadx","checked_epilepsy",1);
7122 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
7123 }
7124 return D_O_K;
7125 }
7126
7127 bool rc = false;
7128
7129 static DIALOG getnum_dlg[] =
7130 {
7131 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
7132 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
7133 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
7134 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
7135 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7136 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7137 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7138 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7139 };
7140
7141 int32_t getnumber(const char *prompt,int32_t initialval)
7142 {
7143 char buf[20];
7144 sprintf(buf,"%d",initialval);
7145 getnum_dlg[0].dp=(void *)prompt;
7146 getnum_dlg[0].dp2=get_zc_font(font_lfont);
7147 getnum_dlg[2].dp=buf;
7148
7149 large_dialog(getnum_dlg);
7150
7151 if(do_zqdialog(getnum_dlg,2)==3)
7152 return atoi(buf);
7153
7154 return initialval;
7155 }
7156
7157 int32_t onLife()
7158 {
7159 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
7160 cheats_enqueue(Cheat::Life, value);
7161 return D_O_K;
7162 }
7163
7164 int32_t onHeartC()
7165 {
7166 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
7167 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
7168 cheats_enqueue(Cheat::MaxLife, max_life);
7169 cheats_enqueue(Cheat::Life, life);
7170 return D_O_K;
7171 }
7172
7173 int32_t onMagicC()
7174 {
7175 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
7176 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
7177 cheats_enqueue(Cheat::MaxMagic, max_magic);
7178 cheats_enqueue(Cheat::Magic, magic);
7179 return D_O_K;
7180 }
7181
7182 int32_t onRupies()
7183 {
7184 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
7185 cheats_enqueue(Cheat::Rupies, value);
7186 return D_O_K;
7187 }
7188
7189 int32_t onMaxBombs()
7190 {
7191 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
7192 cheats_enqueue(Cheat::MaxBombs, value);
7193 cheats_enqueue(Cheat::Bombs, value);
7194 return D_O_K;
7195 }
7196
7197 int32_t onRefillLife()
7198 {
7199 cheats_enqueue(Cheat::Life, game->get_maxlife());
7200 return D_O_K;
7201 }
7202 int32_t onRefillMagic()
7203 {
7204 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
7205 return D_O_K;
7206 }
7207 int32_t onClock()
7208 {
7209 cheats_enqueue(Cheat::Clock);
7210 return D_O_K;
7211 }
7212
7213 int32_t onQstPath()
7214 {
7215 char path[2048];
7216
7217 chop_path(qstdir);
7218 strcpy(path,qstdir);
7219
7220 go();
7221
7222 if(jwin_dfile_select_ex("Quest File Directory", path, "qst", 2048, -1, -1, get_zc_font(font_lfont)))
7223 {
7224 chop_path(path);
7225 fix_filename_case(path);
7226 fix_filename_slashes(path);
7227 strcpy(qstdir,path);
7228 strcpy(qstpath,qstdir);
7229 zc_set_config("zeldadx","quest_dir",qstdir);
7230 flush_config_file();
7231 }
7232
7233 comeback();
7234 return D_O_K;
7235 }
7236
7237 #include "dialog/cheat_dialog.h"
7238 int32_t onCheat()
7239 {
7240 call_setcheat_dialog();
7241 game->set_cheat(maxcheat);
7242 if(cheat) game->did_cheat(true);
7243 return D_O_K;
7244 }
7245
7246 int32_t onCheatRupies()
7247 {
7248 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7249 return D_O_K;
7250 }
7251
7252 int32_t onCheatArrows()
7253 {
7254 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7255 return D_O_K;
7256 }
7257
7258 int32_t onCheatBombs()
7259 {
7260 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7261 return D_O_K;
7262 }
7263
7264 // *** screen saver
7265
7266 9287211 int32_t after_time()
7267 {
7268
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(ss_enable == 0)
7269 return INT_MAX;
7270
7271
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
9287211 if(ss_after <= 0)
7272 return 5 * 60;
7273
7274
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
9287211 if(ss_after <= 3)
7275 return ss_after * 15 * 60;
7276
7277
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
9287211 if(ss_after <= 13)
7278 return (ss_after - 3) * 60 * 60;
7279
7280 9287211 return MAX_IDLE + 1;
7281 9287211 }
7282
7283 static const char *after_str[15] =
7284 {
7285 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7286 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7287 "Never"
7288 };
7289
7290 const char *after_list(int32_t index, int32_t *list_size)
7291 {
7292 if(index < 0)
7293 {
7294 *list_size = 15;
7295 return NULL;
7296 }
7297
7298 return after_str[index];
7299 }
7300
7301 117 static ListData after__list(after_list, &font);
7302
7303 static DIALOG scrsaver_dlg[] =
7304 {
7305 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7306 117 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7307 117 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7308 117 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7309 117 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7310 117 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7311 117 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7312 117 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7313 117 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7314 117 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7315 117 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7316 117 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7317 117 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7318 117 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7319 };
7320
7321 int32_t onScreenSaver()
7322 {
7323 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7324 int32_t oldcfgs[3];
7325 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7326 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7327 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7328
7329 large_dialog(scrsaver_dlg);
7330
7331 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7332
7333 if(ret == 8 || ret == 9)
7334 {
7335 ss_after = scrsaver_dlg[5].d1;
7336 ss_speed = scrsaver_dlg[6].d2;
7337 ss_density = scrsaver_dlg[7].d2;
7338 if(oldcfgs[0] != ss_after)
7339 zc_set_config(cfg_sect,"ss_after",ss_after);
7340 if(oldcfgs[1] != ss_speed)
7341 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7342 if(oldcfgs[2] != ss_density)
7343 zc_set_config(cfg_sect,"ss_density",ss_density);
7344 }
7345
7346 if(ret == 9)
7347 // preview Screen Saver
7348 {
7349 clear_keybuf();
7350 Matrix(ss_speed, ss_density, 30);
7351 system_pal(true);
7352 sys_mouse();
7353 }
7354
7355 return D_O_K;
7356 }
7357
7358 /***** Menus *****/
7359
7360 static MENU game_menu[] =
7361 {
7362 { (char *)"&Continue\tESC", onContinue, NULL, 0, NULL },
7363 { (char *)"", NULL, NULL, 0, NULL },
7364 { (char *)"L&oad Quest...", onCustomGame, NULL, 0, NULL },
7365 { (char *)"&End Game\tF6", onTryQuitMenu, NULL, 0, NULL },
7366 { (char *)"", NULL, NULL, 0, NULL },
7367 #ifdef __EMSCRIPTEN__
7368 { (char *)"&Reset\tF7", onReset, NULL, 0, NULL },
7369 #elif defined(ALLEGRO_MACOSX)
7370 { (char *)"&Reset\tF7", onReset, NULL, 0, NULL },
7371 { (char *)"&Quit\tF8", onExit, NULL, 0, NULL },
7372 #else
7373 { (char *)"&Reset\tF9", onReset, NULL, 0, NULL },
7374 { (char *)"&Quit\tF10", onExit, NULL, 0, NULL },
7375 #endif
7376 { NULL, NULL, NULL, 0, NULL }
7377 };
7378
7379 static MENU snapshot_format_menu[] =
7380 {
7381 { (char *)"&BMP", onSetSnapshotFormat, NULL, 0, NULL },
7382 { (char *)"&GIF", onSetSnapshotFormat, NULL, 0, NULL },
7383 { (char *)"&JPG", onSetSnapshotFormat, NULL, 0, NULL },
7384 { (char *)"&PNG", onSetSnapshotFormat, NULL, 0, NULL },
7385 { (char *)"PC&X", onSetSnapshotFormat, NULL, 0, NULL },
7386 { (char *)"&TGA", onSetSnapshotFormat, NULL, 0, NULL },
7387 { NULL, NULL, NULL, 0, NULL }
7388 };
7389
7390 static MENU controls_menu[] =
7391 {
7392 { (char *)"Key&board...", onKeyboard, NULL, 0, NULL },
7393 { (char *)"&Gamepad...", onGamepad, NULL, 0, NULL },
7394 { (char *)"&Cheat Keys...", onCheatKeys, NULL, 0, NULL },
7395 { NULL, NULL, NULL, 0, NULL }
7396 };
7397
7398 static MENU name_entry_mode_menu[] =
7399 {
7400 { (char *)"&Keyboard", onKeyboardEntry, NULL, 0, NULL },
7401 { (char *)"&Letter Grid", onLetterGridEntry, NULL, 0, NULL },
7402 { (char *)"&Extended Letter Grid", onExtLetterGridEntry, NULL, 0, NULL },
7403 { NULL, NULL, NULL, 0, NULL }
7404 };
7405
7406 static void set_controls_menu_active()
7407 {
7408
7409 }
7410
7411 static MENU window_menu[] =
7412 {
7413 { "Lock Aspect Ratio", onDragAspect, NULL, 0, NULL },
7414 { "Lock Integer Scale", onIntegerScaling, NULL, 0, NULL },
7415 { "Save Size Changes", onSaveDragResize, NULL, 0, NULL },
7416 { "Save Position Changes", onWinPosSave, NULL, 0, NULL },
7417 { "Stretch Game Area", onStretchGame, NULL, 0, NULL },
7418 { NULL, NULL, NULL, 0, NULL }
7419 };
7420 static MENU options_menu[] =
7421 {
7422 { "Name &Entry Mode", NULL, name_entry_mode_menu, 0, NULL },
7423 { "S&napshot Format", NULL, snapshot_format_menu, 0, NULL },
7424 { "&Window Settings", NULL, window_menu, 0, NULL },
7425 { "Epilepsy Flash Reduction", onEpilepsy, NULL, 0, NULL },
7426 { "Pause In Background", onPauseInBackground, NULL, 0, NULL },
7427 { NULL, NULL, NULL, 0, NULL }
7428 };
7429 static MENU settings_menu[] =
7430 {
7431 { "&Sound...", onSound, NULL, 0, NULL },
7432 { "C&ontrols", NULL, controls_menu, 0, NULL },
7433 { "", NULL, NULL, 0, NULL },
7434 { "Options", NULL, options_menu, 0, NULL },
7435 { "", NULL, NULL, 0, NULL },
7436 //
7437 { "&Cap FPS\tF1", onVsync, NULL, 0, NULL },
7438 { "Show &FPS\tF2", onShowFPS, NULL, 0, NULL },
7439 { "Click to Freeze", onClickToFreeze, NULL, 0, NULL },
7440 { "Cont. &Heart Beep", onHeartBeep, NULL, 0, NULL },
7441 { "Show Trans. &Layers", onTransLayers, NULL, 0, NULL },
7442 //
7443 { "Up+A+B To &Quit", onNESquit, NULL, 0, NULL },
7444 { "Volume &Keys", onVolKeys, NULL, 0, NULL },
7445 { "Sa&ve Indicator", onSaveIndicator, NULL, 0, NULL },
7446 { "", NULL, NULL, 0, NULL },
7447 { "Debu&g", onDebug, NULL, 0, NULL },
7448 //
7449 { NULL, NULL, NULL, 0, NULL }
7450 };
7451
7452
7453 static MENU misc_menu[] =
7454 {
7455 { (char *)"&About...", onAbout, NULL, 0, NULL },
7456 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7457 { (char *)"&Credits...", onCredits, NULL, D_DISABLED, NULL },
7458 { (char *)"&Fullscreen", onFullscreenMenu, NULL, 0, NULL },
7459 { (char *)"&Video Mode...", onVidMode, NULL, 0, NULL },
7460 { (char *)"", NULL, NULL, 0, NULL },
7461 //5
7462 { (char *)"&Quest Info...", onQuest, NULL, 0, NULL },
7463 { (char *)"Quest &MIDI Info...", onMIDICredits, NULL, 0, NULL },
7464 { (char *)"Quest &Directory...", onQstPath, NULL, 0, NULL },
7465 { (char *)"", NULL, NULL, 0, NULL },
7466 { (char *)"Take &Snapshot\tF12", onSnapshot, NULL, 0, NULL },
7467 //10
7468 { (char *)"Sc&reen Saver...", onScreenSaver, NULL, 0, NULL },
7469 { (char *)"Save ZC Configuration", OnSaveZCConfig, NULL, 0, NULL },
7470 { (char *)"Show ZASM Debugger", onConsoleZASM, NULL, 0, NULL },
7471 { (char *)"Show ZScript Debugger", onConsoleZScript, NULL, 0, NULL },
7472 { (char *)"Clear Console on Qst Load", onClrConsoleOnLoad, NULL, 0, NULL },
7473 //15
7474 { (char *)"Clear Directory Cache", OnnClearQuestDir, NULL, 0, NULL },
7475 { NULL, NULL, NULL, 0, NULL }
7476 };
7477
7478 static MENU refill_menu[] =
7479 {
7480 { (char *)"&Life", onRefillLife, NULL, 0, NULL },
7481 { (char *)"&Magic", onRefillMagic, NULL, 0, NULL },
7482 { (char *)"&Bombs", onCheatBombs, NULL, 0, NULL },
7483 { (char *)"&Rupees", onCheatRupies, NULL, 0, NULL },
7484 { (char *)"&Arrows", onCheatArrows, NULL, 0, NULL },
7485 { NULL, NULL, NULL, 0, NULL }
7486 };
7487
7488 static MENU show_menu[] =
7489 {
7490 { (char *)"Combos", onShowLayer0, NULL, 0, NULL },
7491 { (char *)"Layer 1", onShowLayer1, NULL, 0, NULL },
7492 { (char *)"Layer 2", onShowLayer2, NULL, 0, NULL },
7493 { (char *)"Layer 3", onShowLayer3, NULL, 0, NULL },
7494 { (char *)"Layer 4", onShowLayer4, NULL, 0, NULL },
7495 { (char *)"Layer 5", onShowLayer5, NULL, 0, NULL },
7496 { (char *)"Layer 6", onShowLayer6, NULL, 0, NULL },
7497 { (char *)"Overhead Combos", onShowLayerO, NULL, 0, NULL },
7498 { (char *)"Push Blocks", onShowLayerP, NULL, 0, NULL },
7499 { (char *)"Freeform Combos", onShowLayerF, NULL, 0, NULL },
7500 { (char *)"Sprites", onShowLayerS, NULL, 0, NULL },
7501 { (char *)"", NULL, NULL, 0, NULL },
7502 { (char *)"Current FFC Scripts", onShowFFScripts, NULL, 0, NULL },
7503 { (char *)"", NULL, NULL, 0, NULL },
7504 { (char *)"Walkability", onShowLayerW, NULL, 0, NULL },
7505 { (char *)"Hitboxes", onShowHitboxes, NULL, 0, NULL },
7506 { (char *)"Effects", onShowLayerE, NULL, 0, NULL },
7507 { (char *)"Info Opacity", onShowInfoOpacity, NULL, 0, NULL },
7508 { NULL, NULL, NULL, 0, NULL }
7509 };
7510
7511 static MENU cheat_menu[] =
7512 {
7513 { (char *)"Set &Cheat", onCheat, NULL, 0, NULL },
7514 { (char *)"", NULL, NULL, 0, NULL },
7515 { (char *)"Re&fill", NULL, refill_menu, 0, NULL },
7516 { (char *)"", NULL, NULL, 0, NULL },
7517 { (char *)"&Invincible", onClock, NULL, 0, NULL },
7518 { (char *)"Ma&x Bombs...", onMaxBombs, NULL, 0, NULL },
7519 { (char *)"&Heart Containers...", onHeartC, NULL, 0, NULL },
7520 { (char *)"&Magic Containers...", onMagicC, NULL, 0, NULL },
7521 { (char *)"", NULL, NULL, 0, NULL },
7522 { (char *)"&Player Data...", onCheatConsole, NULL, 0, NULL },
7523 { (char *)"", NULL, NULL, 0, NULL },
7524 { (char *)"Walk Through &Walls", onNoWalls, NULL, 0, NULL },
7525 { (char *)"Player Ignores Side&view", onIgnoreSideview, NULL, 0, NULL },
7526 { (char *)"&Quick Movement", onGoFast, NULL, 0, NULL },
7527 { (char *)"&Kill All Enemies", onKillCheat, NULL, 0, NULL },
7528 { (char *)"Trigger &Secrets", onSecretsCheat, NULL, 0, NULL },
7529 { (char *)"Trigger Secrets Perm", onSecretsCheatPerm, NULL, 0, NULL },
7530 { (char *)"Show/Hide Layer", NULL, show_menu, 0, NULL },
7531 { (char *)"Toggle &Light", onLightSwitch, NULL, 0, NULL },
7532 { (char *)"&Goto Location...", onGoTo, NULL, 0, NULL },
7533 { NULL, NULL, NULL, 0, NULL }
7534 };
7535
7536 #if DEVLEVEL > 0
7537 int32_t devLogging();
7538 int32_t devDebug();
7539 int32_t devTimestmp();
7540 #if DEVLEVEL > 1
7541 int32_t setCheat();
7542 #endif //DEVLEVEL > 1
7543 enum
7544 {
7545 dv_log,
7546 // dv_dbg,
7547 dv_tmpstmp,
7548 #if DEVLEVEL > 1
7549 dv_nil,
7550 dv_setcheat,
7551 #endif //DEVLEVEL > 1
7552 dv_max
7553 };
7554 static MENU dev_menu[] =
7555 {
7556 { (char *)"&Force Error Log", devLogging, NULL, 0, NULL },
7557 // { (char *)"&Extra Debug Log", devDebug, NULL, 0, NULL },
7558 { (char *)"&Timestamp Log", devTimestmp, NULL, 0, NULL },
7559 #if DEVLEVEL > 1
7560 { (char *)"", NULL, NULL, 0, NULL },
7561 { (char *)"Set &Cheat", setCheat, NULL, 0, NULL },
7562 #endif //DEVLEVEL > 1
7563 { NULL, NULL, NULL, 0, NULL }
7564 };
7565 int32_t devLogging()
7566 {
7567 dev_logging = !dev_logging;
7568 dev_menu[dv_log].flags = dev_logging ? D_SELECTED : 0;
7569 return D_O_K;
7570 }
7571 // int32_t devDebug()
7572 // {
7573 // dev_debug = !dev_debug;
7574 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7575 // return D_O_K;
7576 // }
7577 int32_t devTimestmp()
7578 {
7579 dev_timestmp = !dev_timestmp;
7580 dev_menu[dv_tmpstmp].flags = dev_timestmp ? D_SELECTED : 0;
7581 return D_O_K;
7582 }
7583 #if DEVLEVEL > 1
7584 int32_t setCheat()
7585 {
7586 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7587 return D_O_K;
7588 }
7589 #endif //DEVLEVEL > 1
7590 #endif //DEVLEVEL > 0
7591
7592 MENU the_player_menu[] =
7593 {
7594 { (char *)"&Game", NULL, game_menu, 0, NULL },
7595 { (char *)"&Settings", NULL, settings_menu, 0, NULL },
7596 { (char *)"&Cheat", NULL, cheat_menu, 0, NULL },
7597 { (char *)"Replay", NULL, replay_menu, 0, NULL },
7598 { (char *)"&ZC", NULL, misc_menu, 0, NULL },
7599 #if DEVLEVEL > 0
7600 { (char *)"&Dev", NULL, dev_menu, 0, NULL },
7601 #endif
7602 { NULL, NULL, NULL, 0, NULL }
7603 };
7604 int32_t onPauseInBackground()
7605 {
7606 if(jwin_alert3(
7607 "Toggle Pause In Background",
7608 "This action will change whether ZC Player pauses when the window loses focus.",
7609 "",
7610 "Proceed?",
7611 "&Yes",
7612 "&No",
7613 NULL,
7614 'y',
7615 'n',
7616 0,
7617 get_zc_font(font_lfont)) == 1)
7618 {
7619 pause_in_background = pause_in_background ? 0 : 1;
7620 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7621 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7622 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7623 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7624 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7625 }
7626 options_menu[4].flags =(pause_in_background)?D_SELECTED:0;
7627 return D_O_K;
7628 }
7629
7630 int32_t onKeyboardEntry()
7631 {
7632 NameEntryMode=0;
7633 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7634 return D_O_K;
7635 }
7636
7637 int32_t onLetterGridEntry()
7638 {
7639 NameEntryMode=1;
7640 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7641 return D_O_K;
7642 }
7643
7644 int32_t onExtLetterGridEntry()
7645 {
7646 NameEntryMode=2;
7647 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7648 return D_O_K;
7649 }
7650
7651 static BITMAP* oldscreen;
7652 int32_t onFullscreenMenu()
7653 {
7654 // super hacks
7655 screen = oldscreen;
7656 if (onFullscreen() == D_REDRAW)
7657 {
7658 oldscreen = screen;
7659 }
7660 screen = menu_bmp;
7661 misc_menu[2].flags =(isFullScreen()==1)?D_SELECTED:0;
7662 return D_O_K;
7663 }
7664
7665 117 void fix_menu()
7666 {
7667
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
117 if(!debug_enabled)
7668 117 settings_menu[13].text = NULL;
7669 117 }
7670
7671 static DIALOG system_dlg[] =
7672 {
7673 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
7674 { jwin_menu_proc, 0, 0, 0, 0, 0, 0, 0, D_USER, 0, 0, (void *) the_player_menu, NULL, NULL },
7675 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onVsync, NULL, NULL },
7676 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F2, 0, (void *) onShowFPS, NULL, NULL },
7677 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F6, 0, (void *) onTryQuitMenu, NULL, NULL },
7678 #ifndef ALLEGRO_MACOSX
7679 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F9, 0, (void *) onReset, NULL, NULL },
7680 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F10, 0, (void *) onExit, NULL, NULL },
7681 #else
7682 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F7, 0, (void *) onReset, NULL, NULL },
7683 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F8, 0, (void *) onExit, NULL, NULL },
7684 #endif
7685 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F12, 0, (void *) onSnapshot, NULL, NULL },
7686 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_TAB, 0, (void *) onDebug, NULL, NULL },
7687 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7688 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7689 };
7690
7691 void reset_snapshot_format_menu()
7692 {
7693 for(int32_t i=0; i<ssfmtMAX; ++i)
7694 {
7695 snapshot_format_menu[i].flags=0;
7696 }
7697 }
7698
7699 int32_t onSetSnapshotFormat()
7700 {
7701 switch(active_menu->text[1])
7702 {
7703 case 'B': //"&BMP"
7704 SnapshotFormat=0;
7705 break;
7706
7707 case 'G': //"&GIF"
7708 SnapshotFormat=1;
7709 break;
7710
7711 case 'J': //"&JPG"
7712 SnapshotFormat=2;
7713 break;
7714
7715 case 'P': //"&PNG"
7716 SnapshotFormat=3;
7717 break;
7718
7719 case 'C': //"PC&X"
7720 SnapshotFormat=4;
7721 break;
7722
7723 case 'T': //"&TGA"
7724 SnapshotFormat=5;
7725 break;
7726
7727 case 'L': //"&LBM"
7728 SnapshotFormat=6;
7729 break;
7730 }
7731 zc_set_config("zeldadx", "snapshot_format", SnapshotFormat);
7732
7733 snapshot_format_menu[SnapshotFormat].flags=D_SELECTED;
7734 return D_O_K;
7735 }
7736
7737
7738 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7739 {
7740 PALETTE tmp;
7741
7742 for(int32_t i=0; i<256; i++)
7743 {
7744 tmp[i].r=r;
7745 tmp[i].g=g;
7746 tmp[i].b=b;
7747 }
7748
7749 fade_interpolate(src,tmp,dest,pos,from,to);
7750 }
7751
7752 14 void system_pal(bool force)
7753 {
7754
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 if(is_sys_pal && !force) return;
7755 14 is_sys_pal = true;
7756 14 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7757 14 hw_palette = &syspal;
7758 14 update_hw_pal = true;
7759 14 }
7760
7761 static uint32_t entered_sys_pal = 0;
7762 14 void enter_sys_pal()
7763 {
7764
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(is_sys_pal)
7765 {
7766 if(entered_sys_pal)
7767 ++entered_sys_pal;
7768 return;
7769 }
7770 14 sys_mouse();
7771 14 system_pal(true);
7772 14 ++entered_sys_pal;
7773 14 }
7774 14 void exit_sys_pal()
7775 {
7776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(entered_sys_pal)
7777 {
7778
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!--entered_sys_pal)
7779 {
7780 14 game_pal();
7781 14 game_mouse();
7782 14 }
7783 14 }
7784 14 }
7785
7786 void switch_out_callback()
7787 {
7788 if (pause_in_background && !MenuOpen)
7789 {
7790 System();
7791 }
7792 }
7793
7794 void switch_in_callback()
7795 {
7796 }
7797
7798 424 void game_pal()
7799 {
7800 424 is_sys_pal = false;
7801 424 entered_sys_pal = 0;
7802 424 hw_palette = &RAMpal;
7803 424 update_hw_pal = true;
7804 424 }
7805
7806 static char bar_str[] = "";
7807
7808 14 void music_pause()
7809 {
7810 //al_pause_duh(tmplayer);
7811 14 zcmusic_pause(zcmusic, ZCM_PAUSE);
7812
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(zcmixer->oldtrack)
7813 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7814 14 zc_midi_pause();
7815 14 }
7816
7817 void music_resume()
7818 {
7819 //al_resume_duh(tmplayer);
7820 zcmusic_pause(zcmusic, ZCM_RESUME);
7821 if (zcmixer->oldtrack)
7822 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7823 zc_midi_resume();
7824 }
7825
7826 3361 void music_stop()
7827 {
7828 //al_stop_duh(tmplayer);
7829 //unload_duh(tmusic);
7830 //tmusic=NULL;
7831 //tmplayer=NULL;
7832 3361 zcmusic_stop(zcmusic);
7833 3361 zcmusic_unload_file(zcmusic);
7834
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3361 times.
3361 if (zcmixer->oldtrack)
7835 {
7836 zcmusic_stop(zcmixer->oldtrack);
7837 zcmusic_unload_file(zcmixer->oldtrack);
7838 }
7839 3361 zcmixer->newtrack = NULL;
7840 3361 zc_stop_midi();
7841 3361 currmidi=-1;
7842 3361 }
7843
7844 void System()
7845 {
7846 mouse_down=gui_mouse_b();
7847 music_pause();
7848 pause_all_sfx();
7849 MenuOpen = true;
7850 enter_sys_pal();
7851 // FONT *oldfont=font;
7852 // font=tfont;
7853
7854 misc_menu[2].flags =(isFullScreen()==1)?D_SELECTED:0;
7855 misc_menu[3].flags =(isFullScreen()==1)?D_DISABLED:0;
7856
7857 game_menu[2].flags = getsaveslot() > -1 ? 0 : D_DISABLED;
7858 #if DEVLEVEL > 1
7859 dev_menu[dv_setcheat].flags = Playing ? 0 : D_DISABLED;
7860 #endif
7861 game_menu[3].flags =
7862 misc_menu[5].flags = Playing ? 0 : D_DISABLED;
7863 misc_menu[7].flags = !Playing ? 0 : D_DISABLED;
7864 clear_keybuf();
7865
7866 DIALOG_PLAYER *p;
7867
7868 clear_bitmap(menu_bmp);
7869 oldscreen = screen;
7870 screen = menu_bmp;
7871
7872 p = init_dialog(system_dlg,-1);
7873
7874 // drop the menu on startup if menu button pressed
7875 if(joybtn(Mbtn)||zc_getrawkey(KEY_ESC))
7876 simulate_keypress(KEY_G << 8);
7877
7878 do
7879 {
7880 if(handle_close_btn_quit())
7881 break;
7882
7883 rest(17);
7884
7885 if(mouse_down && !gui_mouse_b())
7886 mouse_down=0;
7887
7888 settings_menu[1].flags = replay_is_replaying() ? D_DISABLED : 0;
7889 settings_menu[5].flags = Throttlefps?D_SELECTED:0;
7890 settings_menu[6].flags = ShowFPS?D_SELECTED:0;
7891 settings_menu[7].flags = ClickToFreeze?D_SELECTED:0;
7892 settings_menu[9].flags = TransLayers?D_SELECTED:0;
7893 settings_menu[10].flags = NESquit?D_SELECTED:0;
7894 settings_menu[11].flags = volkeys?D_SELECTED:0;
7895
7896 window_menu[0].flags = DragAspect?D_SELECTED:0;
7897 window_menu[1].flags = scaleForceInteger?D_SELECTED:0;
7898 window_menu[2].flags = SaveDragResize?D_SELECTED:0;
7899 window_menu[3].flags = SaveWinPos?D_SELECTED:0;
7900 window_menu[4].flags = stretchGame?D_SELECTED:0;
7901
7902 options_menu[3].flags = (epilepsyFlashReduction) ? D_SELECTED : 0;
7903 options_menu[4].flags = (pause_in_background)?D_SELECTED:0;
7904
7905 name_entry_mode_menu[0].flags = (NameEntryMode==0)?D_SELECTED:0;
7906 name_entry_mode_menu[1].flags = (NameEntryMode==1)?D_SELECTED:0;
7907 name_entry_mode_menu[2].flags = (NameEntryMode==2)?D_SELECTED:0;
7908
7909 misc_menu[12].flags =(zasm_debugger)?D_SELECTED:0;
7910 misc_menu[13].flags =(zscript_debugger)?D_SELECTED:0;
7911 misc_menu[14].flags =(clearConsoleOnLoad)?D_SELECTED:0;
7912
7913 bool nocheat = (replay_is_replaying() || !Playing
7914 || (!zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7915 the_player_menu[2].flags = nocheat ? D_DISABLED : 0;
7916 cheat_menu[0].flags = 0;
7917 refill_menu[4].flags = get_qr(qr_TRUEARROWS) ? 0 : D_DISABLED;
7918 cheat_menu[1].text = (cheat >= 1) || get_debug() ? bar_str : NULL;
7919 cheat_menu[3].text = (cheat >= 2) || get_debug() ? bar_str : NULL;
7920 cheat_menu[8].text = (cheat >= 3) || get_debug() ? bar_str : NULL;
7921 cheat_menu[10].text = (cheat >= 4) || get_debug() ? bar_str : NULL;
7922 cheat_menu[4].flags = getClock() ? D_SELECTED : 0;
7923 cheat_menu[11].flags = toogam ? D_SELECTED : 0;
7924 cheat_menu[12].flags = ignoreSideview ? D_SELECTED : 0;
7925 cheat_menu[13].flags = gofast ? D_SELECTED : 0;
7926
7927 show_menu[0].flags = show_layer_0 ? D_SELECTED : 0;
7928 show_menu[1].flags = show_layer_1 ? D_SELECTED : 0;
7929 show_menu[2].flags = show_layer_2 ? D_SELECTED : 0;
7930 show_menu[3].flags = show_layer_3 ? D_SELECTED : 0;
7931 show_menu[4].flags = show_layer_4 ? D_SELECTED : 0;
7932 show_menu[5].flags = show_layer_5 ? D_SELECTED : 0;
7933 show_menu[6].flags = show_layer_6 ? D_SELECTED : 0;
7934 show_menu[7].flags = show_layer_over ? D_SELECTED : 0;
7935 show_menu[8].flags = show_layer_push ? D_SELECTED : 0;
7936 show_menu[9].flags = show_sprites ? D_SELECTED : 0;
7937 show_menu[10].flags = show_ffcs ? D_SELECTED : 0;
7938 show_menu[12].flags = show_walkflags ? D_SELECTED : 0;
7939 show_menu[13].flags = show_ff_scripts ? D_SELECTED : 0;
7940 show_menu[14].flags = show_hitboxes ? D_SELECTED : 0;
7941 show_menu[15].flags = show_effectflags ? D_SELECTED : 0;
7942
7943 settings_menu[8].flags = heart_beep ? D_SELECTED : 0;
7944 settings_menu[12].flags = use_save_indicator ? D_SELECTED : 0;
7945
7946 replay_menu[0].text = zc_get_config("zeldadx", "replay_new_saves", false) ?
7947 (char *)"Disable recording new saves" :
7948 (char *)"Enable recording new saves";
7949 replay_menu[1].flags = replay_is_active() ? 0 : D_DISABLED;
7950 replay_menu[1].text = replay_get_mode() == ReplayMode::Record ?
7951 (char *)"Stop recording" :
7952 (char *)"Stop replaying";
7953 replay_menu[5].flags = replay_get_mode() == ReplayMode::Record ? 0 : D_DISABLED;
7954 replay_menu[6].text = replay_is_snapshot_all_frames() ?
7955 (char *)"Disable snapshot all frames" :
7956 (char *)"Enable snapshot all frames";
7957
7958 reset_snapshot_format_menu();
7959 snapshot_format_menu[SnapshotFormat].flags = D_SELECTED;
7960
7961 if(debug_enabled)
7962 {
7963 settings_menu[14].flags = get_debug() ? D_SELECTED : 0;
7964 }
7965
7966 if(gui_mouse_b() && !mouse_down)
7967 break;
7968
7969 // press menu to drop the menu
7970 if(rMbtn())
7971 simulate_keypress(KEY_G << 8);
7972
7973 if(input_idle(true) > after_time())
7974 // run Screeen Saver
7975 {
7976 // Screen saver enabled for now.
7977 clear_keybuf();
7978 Matrix(ss_speed, ss_density, 0);
7979 system_pal(true);
7980 sys_mouse();
7981 broadcast_dialog_message(MSG_DRAW, 0);
7982 }
7983
7984 update_hw_screen();
7985 }
7986 while(update_dialog(p));
7987
7988 screen = oldscreen;
7989
7990 // font=oldfont;
7991 mouse_down=gui_mouse_b();
7992 shutdown_dialog(p);
7993 MenuOpen = false;
7994 if(Quit)
7995 {
7996 kill_sfx();
7997 music_stop();
7998 update_hw_screen();
7999 }
8000 else
8001 {
8002 music_resume();
8003 resume_all_sfx();
8004
8005 if(rc)
8006 ringcolor(false);
8007 }
8008 exit_sys_pal();
8009
8010 eat_buttons();
8011
8012 rc=false;
8013 clear_keybuf();
8014
8015 zc_init_apply_cheat_delta();
8016 }
8017
8018 117 void fix_dialogs()
8019 {
8020 117 jwin_center_dialog(about_dlg);
8021 117 jwin_center_dialog(gamepad_dlg);
8022 117 jwin_center_dialog(credits_dlg);
8023 117 jwin_center_dialog(gamemode_dlg);
8024 117 jwin_center_dialog(getnum_dlg);
8025 117 jwin_center_dialog(goto_dlg);
8026 117 jwin_center_dialog(keyboard_control_dlg);
8027 117 jwin_center_dialog(midi_dlg);
8028 117 jwin_center_dialog(quest_dlg);
8029 117 jwin_center_dialog(scrsaver_dlg);
8030 117 jwin_center_dialog(sound_dlg);
8031 117 jwin_center_dialog(triforce_dlg);
8032
8033 // digi_dp[1] += scrx;
8034 // digi_dp[2] += scry;
8035 // midi_dp[1] += scrx;
8036 // midi_dp[2] += scry;
8037 // pan_dp[1] += scrx;
8038 // pan_dp[2] += scry;
8039 // emus_dp[1] += scrx;
8040 // emus_dp[2] += scry;
8041 // buf_dp[1] += scrx;
8042 // buf_dp[2] += scry;
8043 // sfx_dp[1] += scrx;
8044 // sfx_dp[2] += scry;
8045 117 }
8046
8047 /*****************************/
8048 /**** Custom Sound System ****/
8049 /*****************************/
8050
8051 117 INLINE int32_t mixvol(int32_t v1,int32_t v2)
8052 {
8053
2/4
✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 117 times.
✗ Branch 3 not taken.
117 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
8054 }
8055
8056 149 int32_t get_emusic_volume()
8057 {
8058 149 int32_t temp_volume = emusic_volume;
8059
2/4
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 149 times.
✗ Branch 3 not taken.
149 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8060 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
8061
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149 times.
149 if (!zcmusic)
8062 149 return temp_volume;
8063 return (temp_volume * zcmusic->fadevolume) / 10000;
8064 149 }
8065
8066 int32_t get_zcmusicpos()
8067 {
8068 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
8069 return debugtracething;
8070 return 0;
8071 }
8072
8073 void set_zcmusicpos(int32_t position)
8074 {
8075 zcmusic_set_curpos(zcmusic, position);
8076 }
8077
8078 void set_zcmusicspeed(int32_t speed)
8079 {
8080 zcmusic_set_speed(zcmusic, speed);
8081 }
8082
8083 int32_t get_zcmusiclen()
8084 {
8085 return zcmusic_get_length(zcmusic);
8086 }
8087
8088 void set_zcmusicloop(double start, double end)
8089 {
8090 zcmusic_set_loop(zcmusic, start, end);
8091 }
8092
8093 63941 void jukebox(int32_t index,int32_t loop)
8094 {
8095
1/2
✓ Branch 0 taken 63941 times.
✗ Branch 1 not taken.
63941 if (is_headless())
8096 63941 return;
8097
8098 music_stop();
8099
8100 if(index<0) index=MAXMIDIS-1;
8101
8102 if(index>=MAXMIDIS) index=0;
8103
8104 music_stop();
8105
8106 // Allegro's DIGMID driver (the one normally used on on Linux) gets
8107 // stuck notes when a song stops. This fixes it.
8108 if(strcmp(midi_driver->name, "DIGMID")==0)
8109 zc_set_volume(0, 0);
8110
8111 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
8112 zc_play_midi((MIDI*)tunes[index].data,loop);
8113
8114 if(tunes[index].start>0)
8115 zc_midi_seek(tunes[index].start);
8116
8117 midi_loop_start = tunes[index].loop_start;
8118 midi_loop_end = tunes[index].loop_end;
8119
8120 currmidi=index;
8121 master_volume(digi_volume, midi_volume);
8122 //midi_paused=false;
8123 63941 }
8124
8125 63941 void jukebox(int32_t index)
8126 {
8127
1/2
✓ Branch 0 taken 63941 times.
✗ Branch 1 not taken.
63941 if(index<0) index=MAXMIDIS-1;
8128
8129
1/2
✓ Branch 0 taken 63941 times.
✗ Branch 1 not taken.
63941 if(index>=MAXMIDIS) index=0;
8130
8131 // do nothing if it's already playing
8132
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 63941 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
63941 if(index==currmidi && midi_pos>=0)
8133 {
8134 return;
8135 }
8136
8137 63941 jukebox(index,tunes[index].loop);
8138 63941 }
8139
8140 16 void play_DmapMusic()
8141 {
8142
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (is_headless())
8143 16 return;
8144
8145 static char tfile[2048];
8146 static int32_t ttrack=0;
8147 bool domidi=false;
8148
8149 int32_t fadeoutframes = 0;
8150 if (zcmusic != NULL)
8151 fadeoutframes = zcmusic->fadeoutframes;
8152
8153 if(DMaps[currdmap].tmusic[0]!=0)
8154 {
8155 if(zcmusic==NULL ||
8156 strcmp(zcmusic->filename,DMaps[currdmap].tmusic)!=0 ||
8157 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[currdmap].tmusictrack))
8158 {
8159 if (DMaps[currdmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
8160 {
8161 if (play_enh_music_crossfade(DMaps[currdmap].tmusic, qstpath, DMaps[currdmap].tmusictrack, get_emusic_volume(), DMaps[currdmap].tmusic_xfade_in, fadeoutframes))
8162 {
8163 if (zcmusic != NULL)
8164 {
8165 zcmusic->fadeoutframes = DMaps[currdmap].tmusic_xfade_out;
8166 zcmusic_set_loop(zcmusic, double(DMaps[currdmap].tmusic_loop_start / 10000.0), double(DMaps[currdmap].tmusic_loop_end / 10000.0));
8167 }
8168 }
8169 }
8170 else
8171 {
8172 if (zcmusic != NULL)
8173 {
8174 zcmusic_stop(zcmusic);
8175 zcmusic_unload_file(zcmusic);
8176 zcmusic = NULL;
8177 zcmixer->newtrack = NULL;
8178 }
8179
8180 zcmusic = zcmusic_load_for_quest(DMaps[currdmap].tmusic, qstpath);
8181 zcmixer->newtrack = zcmusic;
8182
8183 if (zcmusic != NULL)
8184 {
8185 zc_stop_midi();
8186 strcpy(tfile, DMaps[currdmap].tmusic);
8187 zcmusic_play(zcmusic, emusic_volume);
8188 int32_t temptracks = 0;
8189 temptracks = zcmusic_get_tracks(zcmusic);
8190 temptracks = (temptracks < 2) ? 1 : temptracks;
8191 ttrack = vbound(DMaps[currdmap].tmusictrack, 0, temptracks - 1);
8192 zcmusic_change_track(zcmusic, ttrack);
8193 zcmusic_set_loop(zcmusic, double(DMaps[currdmap].tmusic_loop_start / 10000.0), double(DMaps[currdmap].tmusic_loop_end / 10000.0));
8194 }
8195 else
8196 {
8197 tfile[0] = 0;
8198 domidi = true;
8199 }
8200 }
8201 }
8202 }
8203 else
8204 {
8205 if (DMaps[currdmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[currdmap].tmusic) != 0)
8206 {
8207 play_enh_music_crossfade(NULL, qstpath, DMaps[currdmap].tmusictrack, get_emusic_volume(), DMaps[currdmap].tmusic_xfade_in, fadeoutframes);
8208 }
8209 else
8210 {
8211 domidi = true;
8212 }
8213 }
8214
8215 if(domidi)
8216 {
8217 int32_t m=DMaps[currdmap].midi;
8218
8219 switch(m)
8220 {
8221 case 1:
8222 jukebox(ZC_MIDI_OVERWORLD);
8223 break;
8224
8225 case 2:
8226 jukebox(ZC_MIDI_DUNGEON);
8227 break;
8228
8229 case 3:
8230 jukebox(ZC_MIDI_LEVEL9);
8231 break;
8232
8233 default:
8234 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8235 jukebox(m+MIDIOFFSET_DMAP);
8236 else
8237 music_stop();
8238 }
8239 }
8240 16 }
8241
8242 15755 void playLevelMusic()
8243 {
8244
1/2
✓ Branch 0 taken 15755 times.
✗ Branch 1 not taken.
15755 if (is_headless())
8245 15755 return;
8246
8247 int32_t m=tmpscr->screen_midi;
8248
8249 switch(m)
8250 {
8251 case -2:
8252 music_stop();
8253 break;
8254
8255 case -1:
8256 play_DmapMusic();
8257 break;
8258
8259 case 1:
8260 jukebox(ZC_MIDI_OVERWORLD);
8261 break;
8262
8263 case 2:
8264 jukebox(ZC_MIDI_DUNGEON);
8265 break;
8266
8267 case 3:
8268 jukebox(ZC_MIDI_LEVEL9);
8269 break;
8270
8271 default:
8272 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8273 jukebox(m+MIDIOFFSET_MAPSCR);
8274 else
8275 music_stop();
8276 }
8277 15755 }
8278
8279 117 void master_volume(int32_t dv,int32_t mv)
8280 {
8281
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
✓ Branch 2 taken 117 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 117 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 117 times.
✗ Branch 7 not taken.
117 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8282
8283
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
✓ Branch 2 taken 117 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 117 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 117 times.
✗ Branch 7 not taken.
117 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8284
8285
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
✓ Branch 2 taken 117 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 117 times.
117 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8286 117 int32_t temp_vol = midi_volume;
8287
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
117 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8288 117 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8289 117 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8290 117 }
8291
8292 /*****************/
8293 /***** SFX *****/
8294 /*****************/
8295
8296 // array of voices, one for each sfx sample in the data file
8297 // 0+ = voice #
8298 // -1 = voice not allocated
8299 117 void Z_init_sound()
8300 {
8301
2/2
✓ Branch 0 taken 29952 times.
✓ Branch 1 taken 117 times.
30069 for(int32_t i=0; i<WAV_COUNT; i++)
8302 29952 sfx_voice[i]=-1;
8303
8304 117 const char* midis[ZC_MIDI_COUNT] = {
8305 "assets/dungeon.mid",
8306 "assets/ending.mid",
8307 "assets/gameover.mid",
8308 "assets/level9.mid",
8309 "assets/overworld.mid",
8310 "assets/title.mid",
8311 "assets/triforce.mid",
8312 };
8313
2/2
✓ Branch 0 taken 819 times.
✓ Branch 1 taken 117 times.
936 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8314 {
8315 819 tunes[i].data = load_midi(midis[i]);
8316
1/2
✓ Branch 0 taken 819 times.
✗ Branch 1 not taken.
819 if (!tunes[i].data)
8317 Z_error_fatal("Missing required file %s\n", midis[i]);
8318 819 }
8319
8320
2/2
✓ Branch 0 taken 29484 times.
✓ Branch 1 taken 117 times.
29601 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8321 29484 tunes[ZC_MIDI_COUNT+j].data=NULL;
8322
8323 117 master_volume(digi_volume,midi_volume);
8324 117 }
8325
8326 // returns number of voices currently allocated
8327 int32_t sfx_count()
8328 {
8329 int32_t c=0;
8330
8331 for(int32_t i=0; i<WAV_COUNT; i++)
8332 if(sfx_voice[i]!=-1)
8333 ++c;
8334
8335 return c;
8336 }
8337
8338 // clean up finished samples
8339 9218467 void sfx_cleanup()
8340 {
8341
2/2
✓ Branch 0 taken 2359927552 times.
✓ Branch 1 taken 9218467 times.
2369146019 for(int32_t i=0; i<WAV_COUNT; i++)
8342
3/4
✓ Branch 0 taken 619766 times.
✓ Branch 1 taken 2359307786 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 619766 times.
2360547318 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8343 {
8344 619766 deallocate_voice(sfx_voice[i]);
8345 619766 sfx_voice[i]=-1;
8346 619766 }
8347 9218467 }
8348
8349 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8350 // if a voice is already allocated (and/or playing), then it just returns true
8351 // Returns true: voice is allocated
8352 // false: unsuccessful
8353 964184 bool sfx_init(int32_t index)
8354 {
8355 // check index
8356
3/4
✓ Branch 0 taken 721795 times.
✓ Branch 1 taken 242389 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 721795 times.
964184 if(index<=0 || index>=WAV_COUNT)
8357 242389 return false;
8358
8359
2/2
✓ Branch 0 taken 102011 times.
✓ Branch 1 taken 619784 times.
721795 if(sfx_voice[index]==-1)
8360 {
8361
2/2
✓ Branch 0 taken 209876 times.
✓ Branch 1 taken 409908 times.
619784 if(sfxdat)
8362 {
8363
1/2
✓ Branch 0 taken 209876 times.
✗ Branch 1 not taken.
209876 if(index<Z35)
8364 {
8365 209876 sfx_voice[index]=allocate_voice((SAMPLE*)sfxdata[index].dat);
8366 209876 }
8367 else
8368 {
8369 sfx_voice[index]=allocate_voice((SAMPLE*)sfxdata[Z35].dat);
8370 }
8371 209876 }
8372 else
8373 {
8374 409908 sfx_voice[index]=allocate_voice(&customsfxdata[index]);
8375 }
8376
8377 619784 int32_t temp_volume = sfx_volume;
8378
2/4
✓ Branch 0 taken 619784 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 619784 times.
✗ Branch 3 not taken.
619784 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8379 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8380 619784 voice_set_volume(sfx_voice[index], temp_volume);
8381 619784 }
8382
8383 721795 return sfx_voice[index] != -1;
8384 964184 }
8385
8386 int32_t sfx_get_default_freq(int32_t index)
8387 {
8388 if (sfxdat)
8389 {
8390 if (index < Z35)
8391 {
8392 return ((SAMPLE*)sfxdata[index].dat)->freq;
8393 }
8394 else
8395 {
8396 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8397 }
8398 }
8399 else
8400 {
8401 return customsfxdata[index].freq;
8402 }
8403 }
8404
8405 int32_t sfx_get_length(int32_t index)
8406 {
8407 if (sfxdat)
8408 {
8409 if (index < Z35)
8410 {
8411 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8412 }
8413 else
8414 {
8415 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8416 }
8417 }
8418 else
8419 {
8420 return int32_t(customsfxdata[index].len);
8421 }
8422 }
8423
8424 // plays an sfx sample
8425 964184 void sfx(int32_t index,int32_t pan,bool loop, bool restart, int32_t vol, int32_t freq)
8426 {
8427
2/2
✓ Branch 0 taken 721795 times.
✓ Branch 1 taken 242389 times.
964184 if(!sfx_init(index))
8428 242389 return;
8429
1/2
✓ Branch 0 taken 721795 times.
✗ Branch 1 not taken.
721795 if (!is_headless())
8430 {
8431 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8432 voice_set_pan(sfx_voice[index], pan);
8433
8434 // Only used by ZScript currently
8435 if (freq <= -1)
8436 {
8437 freq = sfx_get_default_freq(index);
8438 }
8439 voice_set_frequency(sfx_voice[index], freq);
8440
8441 // Only used by ZScript currently
8442 int32_t temp_volume = (sfx_volume * vol) / 10000 / 100;
8443 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8444 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8445 voice_set_volume(sfx_voice[index], temp_volume);
8446
8447 int32_t pos = voice_get_position(sfx_voice[index]);
8448
8449 if (restart) voice_set_position(sfx_voice[index], 0);
8450
8451 if (pos <= 0)
8452 voice_start(sfx_voice[index]);
8453 }
8454
8455
3/4
✓ Branch 0 taken 398004 times.
✓ Branch 1 taken 323791 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 398004 times.
721795 if (restart && replay_is_debug())
8456
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 398004 times.
398004 replay_step_comment(fmt::format("sfx {}", sfx_string[index]));
8457 964184 }
8458
8459 // true if sfx is allocated
8460 68052 bool sfx_allocated(int32_t index)
8461 {
8462
3/4
✓ Branch 0 taken 9923 times.
✓ Branch 1 taken 58129 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9923 times.
68052 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8463 }
8464
8465 // start it (in loop mode) if it's not already playing,
8466 // otherwise adjust it to play in loop mode -DD
8467 55174 void cont_sfx(int32_t index)
8468 {
8469
1/2
✓ Branch 0 taken 55174 times.
✗ Branch 1 not taken.
55174 if (is_headless())
8470 55174 return;
8471
8472 if(!sfx_init(index))
8473 {
8474 return;
8475 }
8476
8477 if(voice_get_position(sfx_voice[index])<=0)
8478 {
8479 voice_set_position(sfx_voice[index],0);
8480 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8481 voice_start(sfx_voice[index]);
8482 }
8483 else
8484 {
8485 adjust_sfx(index, 128, true);
8486 }
8487 55174 }
8488
8489 // adjust parameters while playing
8490 4075 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8491 {
8492
4/6
✓ Branch 0 taken 2315 times.
✓ Branch 1 taken 1760 times.
✓ Branch 2 taken 2315 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2315 times.
4075 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8493 4075 return;
8494
8495 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8496 voice_set_pan(sfx_voice[index],pan);
8497 4075 }
8498
8499 // pauses a voice
8500 1725 void pause_sfx(int32_t index)
8501 {
8502
3/6
✓ Branch 0 taken 1725 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1725 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1725 times.
1725 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8503 voice_stop(sfx_voice[index]);
8504 1725 }
8505
8506 // resumes a voice
8507 747 void resume_sfx(int32_t index)
8508 {
8509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 747 times.
747 if (is_headless())
8510 747 return;
8511
8512 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8513 voice_start(sfx_voice[index]);
8514 747 }
8515
8516 // pauses all active voices
8517 452 void pause_all_sfx()
8518 {
8519
2/2
✓ Branch 0 taken 115712 times.
✓ Branch 1 taken 452 times.
116164 for(int32_t i=0; i<WAV_COUNT; i++)
8520
2/2
✓ Branch 0 taken 115711 times.
✓ Branch 1 taken 1 times.
115713 if(sfx_voice[i]!=-1)
8521 1 voice_stop(sfx_voice[i]);
8522 452 }
8523
8524 // resumes all paused voices
8525 438 void resume_all_sfx()
8526 {
8527
2/2
✓ Branch 0 taken 112128 times.
✓ Branch 1 taken 438 times.
112566 for(int32_t i=0; i<WAV_COUNT; i++)
8528
1/2
✓ Branch 0 taken 112128 times.
✗ Branch 1 not taken.
112128 if(sfx_voice[i]!=-1)
8529 voice_start(sfx_voice[i]);
8530 438 }
8531
8532 // stops an sfx and deallocates the voice
8533 7462663 void stop_sfx(int32_t index)
8534 {
8535
3/4
✓ Branch 0 taken 6277597 times.
✓ Branch 1 taken 1185066 times.
✓ Branch 2 taken 6277597 times.
✗ Branch 3 not taken.
7462663 if(index<=0 || index>=WAV_COUNT)
8536 1185066 return;
8537
8538
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6277585 times.
6277597 if(sfx_voice[index]!=-1)
8539 {
8540 12 deallocate_voice(sfx_voice[index]);
8541 12 sfx_voice[index]=-1;
8542 12 }
8543 7462663 }
8544
8545 // Stops SFX played by Hero's item of the given family
8546 128638 void stop_item_sfx(int32_t family)
8547 {
8548 128638 int32_t id=current_item_id(family);
8549
8550
2/2
✓ Branch 0 taken 128083 times.
✓ Branch 1 taken 555 times.
128638 if(id<0)
8551 128083 return;
8552
8553 555 stop_sfx(itemsbuf[id].usesound);
8554 128638 }
8555
8556 3223 void kill_sfx()
8557 {
8558
2/2
✓ Branch 0 taken 825088 times.
✓ Branch 1 taken 3223 times.
828311 for(int32_t i=0; i<WAV_COUNT; i++)
8559
2/2
✓ Branch 0 taken 825082 times.
✓ Branch 1 taken 6 times.
825094 if(sfx_voice[i]!=-1)
8560 {
8561 6 deallocate_voice(sfx_voice[i]);
8562 6 sfx_voice[i]=-1;
8563 6 }
8564 3223 }
8565
8566 659811 int32_t pan(int32_t x)
8567 {
8568
1/4
✓ Branch 0 taken 659811 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
659811 switch(pan_style)
8569 {
8570 case 0:
8571 return 128;
8572
8573 case 1:
8574 659811 return vbound((x>>1)+68,0,255);
8575
8576 case 2:
8577 return vbound(((x*3)>>2)+36,0,255);
8578 }
8579
8580 return vbound(x,0,255);
8581 659811 }
8582
8583 /*******************************/
8584 /******* Input Handlers ********/
8585 /*******************************/
8586
8587 25094006 bool joybtn(int32_t b)
8588 {
8589
1/2
✓ Branch 0 taken 25094006 times.
✗ Branch 1 not taken.
25094006 if(b == 0)
8590 return false;
8591
1/2
✓ Branch 0 taken 25094006 times.
✗ Branch 1 not taken.
25094006 if (b-1 >= joy[joystick_index].num_buttons)
8592 25094006 return false;
8593
8594 return joy[joystick_index].button[b-1].b !=0;
8595 25094006 }
8596
8597 bool joystick(int32_t s)
8598 {
8599 if(s < 0)
8600 return false;
8601 if (s >= joy[joystick_index].num_sticks)
8602 return false;
8603
8604 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8605 {
8606 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8607 return true;
8608 }
8609 return false;
8610 }
8611
8612 const char* joybtn_name(int32_t b)
8613 {
8614 if (b <= 0 || b > joy[joystick_index].num_buttons)
8615 return "";
8616
8617 return joy[joystick_index].button[b-1].name;
8618 }
8619
8620 const char* joystick_name(int32_t s)
8621 {
8622 if (s < 0 || s >= joy[joystick_index].num_sticks)
8623 return "";
8624
8625 return joy[joystick_index].stick[s].name;
8626 }
8627
8628 int32_t next_press_key();
8629
8630 int32_t next_joy_input(bool buttons)
8631 {
8632 clear_keybuf();
8633
8634 //first, we need to wait until they're pressing no buttons
8635 for(;;)
8636 {
8637 if(keypressed())
8638 {
8639 switch(readkey()>>8)
8640 {
8641 case KEY_ESC:
8642 return -1;
8643
8644 case KEY_SPACE:
8645 return 0;
8646 }
8647 }
8648
8649 poll_joystick();
8650 bool done = true;
8651
8652 if (buttons)
8653 {
8654 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8655 {
8656 if(joybtn(i)) done = false;
8657 }
8658 }
8659 else
8660 {
8661 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8662 {
8663 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8664 return -2;
8665 }
8666 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8667 {
8668 if(joystick(i)) done = false;
8669 }
8670 }
8671
8672 if(done) break;
8673 rest(1);
8674 }
8675
8676 //now, we need to wait for them to press any button
8677 for(;;)
8678 {
8679 if(keypressed())
8680 {
8681 switch(readkey()>>8)
8682 {
8683 case KEY_ESC:
8684 return -1;
8685
8686 case KEY_SPACE:
8687 return 0;
8688 }
8689 }
8690
8691 poll_joystick();
8692
8693 if (buttons)
8694 {
8695 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8696 {
8697 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8698 return -2;
8699 }
8700 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8701 {
8702 if(joybtn(i))
8703 return i;
8704 }
8705 }
8706 else
8707 {
8708 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8709 {
8710 if(joystick(i))
8711 return i;
8712 }
8713 }
8714 rest(1);
8715 }
8716 }
8717
8718 1209106 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8719 {
8720
2/2
✓ Branch 0 taken 1204755 times.
✓ Branch 1 taken 4351 times.
1209106 bool ret = btn && !flag;
8721 1209106 flag = rawbtn;
8722
8723 1209106 return ret;
8724 }
8725 190805710 static bool rButton(bool &btn, bool &flag)
8726 {
8727
2/2
✓ Branch 0 taken 183961269 times.
✓ Branch 1 taken 6844441 times.
190805710 bool ret = btn && !flag;
8728 190805710 flag = btn;
8729
8730 190805710 return ret;
8731 }
8732 2888985 static bool rButtonPeek(bool btn, bool flag)
8733 {
8734
2/2
✓ Branch 0 taken 2685887 times.
✓ Branch 1 taken 203098 times.
2888985 if(!btn)
8735 {
8736 2685887 return false;
8737 }
8738
2/2
✓ Branch 0 taken 17939 times.
✓ Branch 1 taken 185159 times.
203098 else if(!flag)
8739 {
8740 17939 return true;
8741 }
8742
8743 185159 return false;
8744 2888985 }
8745
8746 // Updated only by keyboard/gamepad.
8747 // If in replay mode, this is set directly by the replay system.
8748 // This should never be read from directly - use control_state instead.
8749 bool raw_control_state[ZC_CONTROL_STATES];
8750
8751 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8752 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8753 // lasts until the next call to load_control_state.
8754 bool control_state[ZC_CONTROL_STATES];
8755 bool disable_control[ZC_CONTROL_STATES];
8756 bool drunk_toggle_state[11];
8757 bool disabledKeys[127];
8758 bool KeyInput[127];
8759 bool KeyPress[127];
8760
8761 bool key_current_frame[127];
8762 bool key_previous_frame[127];
8763
8764 static bool key_system[127];
8765 static bool key_system_previous[127];
8766 static bool key_system_press[127];
8767
8768 bool button_press[ZC_CONTROL_STATES];
8769 bool button_hold[ZC_CONTROL_STATES];
8770
8771 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8772 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8773 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8774 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8775 #define STICK_PRECISION 56 //define your own sensitivity
8776
8777 7801176 void load_control_state()
8778 {
8779 7801176 load_control_called_this_frame = true;
8780
8781
2/2
✓ Branch 0 taken 4833663 times.
✓ Branch 1 taken 2967513 times.
7801176 if (replay_version_check(8, 11))
8782 {
8783
2/2
✓ Branch 0 taken 53415234 times.
✓ Branch 1 taken 2967513 times.
56382747 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8784 53415234 down_control_states[i] = raw_control_state[i];
8785 2967513 }
8786
8787
1/2
✓ Branch 0 taken 7801176 times.
✗ Branch 1 not taken.
7801176 if (!replay_is_replaying())
8788 {
8789 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8790 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8791 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8792 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8793 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8794 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8795 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8796 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8797 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8798 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8799 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8800 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8801 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8802 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8803
8804 if(num_joysticks != 0)
8805 {
8806 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8807 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8808 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8809 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8810 // zprint2("Detected %d joysticks... %d%d%d%d\n", num_joysticks, raw_control_state[14]?1:0, raw_control_state[15]?1:0, raw_control_state[16]?1:0, raw_control_state[17]?1:0);
8811 }
8812 else
8813 {
8814 raw_control_state[14] = false;
8815 raw_control_state[15] = false;
8816 raw_control_state[16] = false;
8817 raw_control_state[17] = false;
8818 // zprint2("Detected 0 joysticks... clearing inputaxis values.\n");
8819 }
8820 }
8821
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7801173 times.
7801176 if (replay_is_active())
8822 {
8823
2/2
✓ Branch 0 taken 1015215 times.
✓ Branch 1 taken 6785958 times.
7801173 if (replay_get_version() < 3)
8824 1015215 replay_poll();
8825
3/4
✓ Branch 0 taken 6785958 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5024583 times.
✓ Branch 3 taken 1761375 times.
6785958 else if (replay_is_replaying() && replay_get_version() < 6)
8826 1761375 replay_peek_input();
8827
3/4
✓ Branch 0 taken 5024583 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2057070 times.
✓ Branch 3 taken 2967513 times.
5024583 else if (replay_is_replaying() && replay_version_check(8, 11))
8828 2967513 replay_peek_input();
8829
2/2
✓ Branch 0 taken 6696883 times.
✓ Branch 1 taken 1104290 times.
7801173 if (replay_get_version() == 8)
8830 1104290 update_keys();
8831 7801173 }
8832
8833 // Some test replay files were made before a serious input bug was fixed, so instead
8834 // of re-doing them or tossing them out, just check for that zplay version.
8835
3/4
✓ Branch 0 taken 7801170 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 7679270 times.
7801176 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8836
2/2
✓ Branch 0 taken 140421060 times.
✓ Branch 1 taken 7801170 times.
148222230 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8837 {
8838 140421060 control_state[i] = raw_control_state[i];
8839
4/4
✓ Branch 0 taken 49487310 times.
✓ Branch 1 taken 90933750 times.
✓ Branch 2 taken 2410168 times.
✓ Branch 3 taken 47077142 times.
140421060 if (botched_input && !control_state[i])
8840 47077142 down_control_states[i] = false;
8841 140421060 }
8842 7801170 bool did_bad_cutscene_btn = false;
8843
2/2
✓ Branch 0 taken 7801170 times.
✓ Branch 1 taken 140421060 times.
148222230 for(int q = 0; q < 18; ++q)
8844
4/4
✓ Branch 0 taken 6465003 times.
✓ Branch 1 taken 133956057 times.
✓ Branch 2 taken 6464269 times.
✓ Branch 3 taken 734 times.
140421794 if(control_state[q] && !active_cutscene.can_button(q))
8845 {
8846 734 control_state[q] = false;
8847 734 did_bad_cutscene_btn = true;
8848 734 }
8849
2/2
✓ Branch 0 taken 7800655 times.
✓ Branch 1 taken 515 times.
7801170 if(did_bad_cutscene_btn)
8850 515 active_cutscene.error();
8851
8852 7801170 button_press[0]=rButton(control_state[0],button_hold[0]);
8853 7801170 button_press[1]=rButton(control_state[1],button_hold[1]);
8854 7801170 button_press[2]=rButton(control_state[2],button_hold[2]);
8855 7801170 button_press[3]=rButton(control_state[3],button_hold[3]);
8856 7801170 button_press[4]=rButton(control_state[4],button_hold[4]);
8857 7801170 button_press[5]=rButton(control_state[5],button_hold[5]);
8858 7801170 button_press[6]=rButton(control_state[6],button_hold[6]);
8859 7801170 button_press[7]=rButton(control_state[7],button_hold[7]);
8860 7801170 button_press[8]=rButton(control_state[8],button_hold[8]);
8861 7801170 button_press[9]=rButton(control_state[9],button_hold[9]);
8862 7801170 button_press[10]=rButton(control_state[10],button_hold[10]);
8863 7801170 button_press[11]=rButton(control_state[11],button_hold[11]);
8864 7801170 button_press[12]=rButton(control_state[12],button_hold[12]);
8865 7801170 button_press[13]=rButton(control_state[13],button_hold[13]);
8866 7801170 button_press[14]=rButton(control_state[14],button_hold[14]);
8867 7801170 button_press[15]=rButton(control_state[15],button_hold[15]);
8868 7801170 button_press[16]=rButton(control_state[16],button_hold[16]);
8869 7801170 button_press[17]=rButton(control_state[17],button_hold[17]);
8870 7801170 }
8871
8872 // Returns true if any game key is pressed. This is needed because keypressed()
8873 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8874 40250637 bool zc_key_pressed()
8875 //may also need to use zc_getrawkey
8876 {
8877
7/10
✓ Branch 0 taken 32597771 times.
✓ Branch 1 taken 7652866 times.
✓ Branch 2 taken 7652866 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7652866 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6396392 times.
✓ Branch 7 taken 6396392 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2461754 times.
42712391 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8878
4/6
✓ Branch 0 taken 6396392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6396392 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4844168 times.
✓ Branch 5 taken 4844168 times.
6396392 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8879
4/6
✓ Branch 0 taken 4844168 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4844168 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3143220 times.
✓ Branch 5 taken 3143220 times.
4844168 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8880
4/6
✓ Branch 0 taken 3143220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3143220 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2732278 times.
✓ Branch 5 taken 2732278 times.
3143220 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8881
1/2
✓ Branch 0 taken 2732278 times.
✗ Branch 1 not taken.
2732278 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8882
3/4
✓ Branch 0 taken 2612871 times.
✓ Branch 1 taken 119407 times.
✓ Branch 2 taken 2612871 times.
✗ Branch 3 not taken.
2732278 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8883
3/4
✓ Branch 0 taken 2493968 times.
✓ Branch 1 taken 118903 times.
✓ Branch 2 taken 2493968 times.
✗ Branch 3 not taken.
2612871 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8884
3/4
✓ Branch 0 taken 2478823 times.
✓ Branch 1 taken 15145 times.
✓ Branch 2 taken 2478823 times.
✗ Branch 3 not taken.
2493968 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8885
3/4
✓ Branch 0 taken 2465324 times.
✓ Branch 1 taken 13499 times.
✓ Branch 2 taken 2465324 times.
✗ Branch 3 not taken.
2478823 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8886
3/4
✓ Branch 0 taken 2462830 times.
✓ Branch 1 taken 2494 times.
✓ Branch 2 taken 2462830 times.
✗ Branch 3 not taken.
2465324 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8887
3/4
✓ Branch 0 taken 2462612 times.
✓ Branch 1 taken 218 times.
✓ Branch 2 taken 2462612 times.
✗ Branch 3 not taken.
2462830 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8888
3/4
✓ Branch 0 taken 2461773 times.
✓ Branch 1 taken 839 times.
✓ Branch 2 taken 2461773 times.
✗ Branch 3 not taken.
2462612 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8889
2/4
✓ Branch 0 taken 2461773 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2461773 times.
✗ Branch 3 not taken.
2461773 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8890
2/2
✓ Branch 0 taken 2461754 times.
✓ Branch 1 taken 19 times.
2461773 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8891 72020999 return true;
8892
8893 2461754 return false;
8894 9287211 }
8895
8896 149956017 bool getInput(int32_t btn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8897 {
8898 149956017 bool ret = false, drunkstate = false, rawret = false;;
8899 149956017 bool* flag = &down_control_states[btn];
8900
2/7
✓ Branch 0 taken 140659469 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 9296548 times.
149956017 switch(btn)
8901 {
8902 case btnF12:
8903 ret = zc_getkey(KEY_F12, ignoreDisable);
8904 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8905 eatEntirely = false;
8906 break;
8907 case btnF11:
8908 ret = zc_getkey(KEY_F11, ignoreDisable);
8909 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8910 eatEntirely = false;
8911 break;
8912 case btnF5:
8913 ret = zc_getkey(KEY_F5, ignoreDisable);
8914 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8915 eatEntirely = false;
8916 break;
8917 case btnQ:
8918 ret = zc_getkey(KEY_Q, ignoreDisable);
8919 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8920 eatEntirely = false;
8921 break;
8922 case btnI:
8923 ret = zc_getkey(KEY_I, ignoreDisable);
8924 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8925 eatEntirely = false;
8926 break;
8927 case btnM:
8928
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9296548 times.
9296548 if(FFCore.kb_typing_mode) return false;
8929 9296548 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8930 9296548 eatEntirely = false;
8931 9296548 break;
8932 default: //control_state[] index
8933
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 140659469 times.
140659469 if(FFCore.kb_typing_mode) return false;
8934
5/6
✓ Branch 0 taken 139859690 times.
✓ Branch 1 taken 799779 times.
✓ Branch 2 taken 2237468 times.
✓ Branch 3 taken 137622222 times.
✓ Branch 4 taken 2237468 times.
✗ Branch 5 not taken.
140659469 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8935
2/2
✓ Branch 0 taken 8036378 times.
✓ Branch 1 taken 132623091 times.
140659469 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8936
4/4
✓ Branch 0 taken 126521127 times.
✓ Branch 1 taken 14138342 times.
✓ Branch 2 taken 3004 times.
✓ Branch 3 taken 14135338 times.
154797811 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8937 140659469 rawret = raw_control_state[btn];
8938 140659469 }
8939
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149956017 times.
149956017 assert(flag);
8940
2/2
✓ Branch 0 taken 95473276 times.
✓ Branch 1 taken 54482741 times.
149956017 if(press)
8941 {
8942
2/2
✓ Branch 0 taken 2888985 times.
✓ Branch 1 taken 51593756 times.
54482741 if(peek)
8943 2888985 ret = rButtonPeek(ret, *flag);
8944
2/2
✓ Branch 0 taken 50384650 times.
✓ Branch 1 taken 1209106 times.
51593756 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
8945 1209106 else ret = rButton(ret, *flag, rawret);
8946 54482741 }
8947
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 149956017 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
149956017 if(eatEntirely && ret) control_state[btn] = false;
8948
3/4
✓ Branch 0 taken 112376241 times.
✓ Branch 1 taken 37579776 times.
✓ Branch 2 taken 112376241 times.
✗ Branch 3 not taken.
149956017 if(drunk && drunkstate) ret = !ret;
8949 149956017 return ret;
8950 149956017 }
8951
8952 7465295 byte getIntBtnInput(byte intbtn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8953 {
8954 7465295 byte ret = 0;
8955
2/2
✓ Branch 0 taken 5485975 times.
✓ Branch 1 taken 1979320 times.
7465295 if(intbtn & INT_BTN_A) ret |= getInput(btnA, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_A : 0;
8956
2/2
✓ Branch 0 taken 7334481 times.
✓ Branch 1 taken 130814 times.
7465295 if(intbtn & INT_BTN_B) ret |= getInput(btnB, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_B : 0;
8957
2/2
✓ Branch 0 taken 7334606 times.
✓ Branch 1 taken 130689 times.
7465295 if(intbtn & INT_BTN_L) ret |= getInput(btnL, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_L : 0;
8958
2/2
✓ Branch 0 taken 7334606 times.
✓ Branch 1 taken 130689 times.
7465295 if(intbtn & INT_BTN_R) ret |= getInput(btnR, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_R : 0;
8959
2/2
✓ Branch 0 taken 7334606 times.
✓ Branch 1 taken 130689 times.
7465295 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX1 : 0;
8960
2/2
✓ Branch 0 taken 7334606 times.
✓ Branch 1 taken 130689 times.
7465295 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX2 : 0;
8961
2/2
✓ Branch 0 taken 7334606 times.
✓ Branch 1 taken 130689 times.
7465295 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX3 : 0;
8962
2/2
✓ Branch 0 taken 7334606 times.
✓ Branch 1 taken 130689 times.
7465295 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX4 : 0;
8963 7465295 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
8964 }
8965
8966 1114 byte checkIntBtnVal(byte intbtn, byte vals)
8967 {
8968 1114 return intbtn&vals;
8969 }
8970
8971 1767437 bool Up()
8972 {
8973 1767437 return getInput(btnUp);
8974 }
8975 147234 bool Down()
8976 {
8977 147234 return getInput(btnDown);
8978 }
8979 257723 bool Left()
8980 {
8981 257723 return getInput(btnLeft);
8982 }
8983 286925 bool Right()
8984 {
8985 286925 return getInput(btnRight);
8986 }
8987 164908 bool cAbtn()
8988 {
8989 164908 return getInput(btnA);
8990 }
8991 1411891 bool cBbtn()
8992 {
8993 1411891 return getInput(btnB);
8994 }
8995 bool cSbtn()
8996 {
8997 return getInput(btnS);
8998 }
8999 68744 bool cLbtn()
9000 {
9001 68744 return getInput(btnL);
9002 }
9003 68744 bool cRbtn()
9004 {
9005 68744 return getInput(btnR);
9006 }
9007 bool cPbtn()
9008 {
9009 return getInput(btnP);
9010 }
9011 bool cEx1btn()
9012 {
9013 return getInput(btnEx1);
9014 }
9015 bool cEx2btn()
9016 {
9017 return getInput(btnEx2);
9018 }
9019 bool cEx3btn()
9020 {
9021 return getInput(btnEx3);
9022 }
9023 bool cEx4btn()
9024 {
9025 return getInput(btnEx4);
9026 }
9027 bool AxisUp()
9028 {
9029 return getInput(btnAxisUp);
9030 }
9031 bool AxisDown()
9032 {
9033 return getInput(btnAxisDown);
9034 }
9035 bool AxisLeft()
9036 {
9037 return getInput(btnAxisLeft);
9038 }
9039 bool AxisRight()
9040 {
9041 return getInput(btnAxisRight);
9042 }
9043
9044 bool cMbtn()
9045 {
9046 return getInput(btnM);
9047 }
9048 bool cF12()
9049 {
9050 return getInput(btnF12);
9051 }
9052 bool cF11()
9053 {
9054 return getInput(btnF11);
9055 }
9056 bool cF5()
9057 {
9058 return getInput(btnF5);
9059 }
9060 bool cQ()
9061 {
9062 return getInput(btnQ);
9063 }
9064 bool cI()
9065 {
9066 return getInput(btnI);
9067 }
9068
9069 130270 bool rUp()
9070 {
9071 130270 return getInput(btnUp, true);
9072 }
9073 130174 bool rDown()
9074 {
9075 130174 return getInput(btnDown, true);
9076 }
9077 130122 bool rLeft()
9078 {
9079 130122 return getInput(btnLeft, true);
9080 }
9081 129657 bool rRight()
9082 {
9083 129657 return getInput(btnRight, true);
9084 }
9085 1296 bool rAbtn()
9086 {
9087 1296 return getInput(btnA, true);
9088 }
9089 1296 bool rBbtn()
9090 {
9091 1296 return getInput(btnB, true);
9092 }
9093 7397110 bool rSbtn()
9094 {
9095 7397110 return getInput(btnS, true);
9096 }
9097 9287211 bool rMbtn()
9098 {
9099 9287211 return getInput(btnM, true);
9100 }
9101 129441 bool rLbtn()
9102 {
9103 129441 return getInput(btnL, true);
9104 }
9105 129436 bool rRbtn()
9106 {
9107 129436 return getInput(btnR, true);
9108 }
9109 7333574 bool rPbtn()
9110 {
9111 7333574 return getInput(btnP, true);
9112 }
9113 bool rEx1btn()
9114 {
9115 return getInput(btnEx1, true);
9116 }
9117 bool rEx2btn()
9118 {
9119 return getInput(btnEx2, true);
9120 }
9121 140087 bool rEx3btn()
9122 {
9123 140087 return getInput(btnEx3, true);
9124 }
9125 140087 bool rEx4btn()
9126 {
9127 140087 return getInput(btnEx4, true);
9128 }
9129 bool rAxisUp()
9130 {
9131 return getInput(btnAxisUp, true);
9132 }
9133 bool rAxisDown()
9134 {
9135 return getInput(btnAxisDown, true);
9136 }
9137 bool rAxisLeft()
9138 {
9139 return getInput(btnAxisLeft, true);
9140 }
9141 bool rAxisRight()
9142 {
9143 return getInput(btnAxisRight, true);
9144 }
9145
9146 bool rF11()
9147 {
9148 return getInput(btnF11, true);
9149 }
9150 bool rQ()
9151 {
9152 return getInput(btnQ, true);
9153 }
9154 bool rI()
9155 {
9156 return getInput(btnI, true);
9157 }
9158
9159 18227830 bool DrunkUp()
9160 {
9161 18227830 return getInput(btnUp, false, true);
9162 }
9163 16890614 bool DrunkDown()
9164 {
9165 16890614 return getInput(btnDown, false, true);
9166 }
9167 10289030 bool DrunkLeft()
9168 {
9169 10289030 return getInput(btnLeft, false, true);
9170 }
9171 8834523 bool DrunkRight()
9172 {
9173 8834523 return getInput(btnRight, false, true);
9174 }
9175 8036020 bool DrunkcAbtn()
9176 {
9177 8036020 return getInput(btnA, false, true);
9178 }
9179 8017468 bool DrunkcBbtn()
9180 {
9181 8017468 return getInput(btnB, false, true);
9182 }
9183 7264444 bool DrunkcEx1btn()
9184 {
9185 7264444 return getInput(btnEx1, false, true);
9186 }
9187 7264464 bool DrunkcEx2btn()
9188 {
9189 7264464 return getInput(btnEx2, false, true);
9190 }
9191 bool DrunkcSbtn()
9192 {
9193 return getInput(btnS, false, true);
9194 }
9195 bool DrunkcMbtn()
9196 {
9197 return getInput(btnM, false, true);
9198 }
9199 bool DrunkcLbtn()
9200 {
9201 return getInput(btnL, false, true);
9202 }
9203 bool DrunkcRbtn()
9204 {
9205 return getInput(btnR, false, true);
9206 }
9207 bool DrunkcPbtn()
9208 {
9209 return getInput(btnP, false, true);
9210 }
9211
9212 bool DrunkrUp()
9213 {
9214 return getInput(btnUp, true, true);
9215 }
9216 bool DrunkrDown()
9217 {
9218 return getInput(btnDown, true, true);
9219 }
9220 bool DrunkrLeft()
9221 {
9222 return getInput(btnLeft, true, true);
9223 }
9224 bool DrunkrRight()
9225 {
9226 return getInput(btnRight, true, true);
9227 }
9228 6082228 bool DrunkrAbtn()
9229 {
9230 6082228 return getInput(btnA, true, true);
9231 }
9232 6099060 bool DrunkrBbtn()
9233 {
9234 6099060 return getInput(btnB, true, true);
9235 }
9236 71669 bool DrunkrEx1btn()
9237 {
9238 71669 return getInput(btnEx1, true, true);
9239 }
9240 71662 bool DrunkrEx2btn()
9241 {
9242 71662 return getInput(btnEx2, true, true);
9243 }
9244 bool DrunkrEx3btn()
9245 {
9246 return getInput(btnEx3, true, true);
9247 }
9248 bool DrunkrEx4btn()
9249 {
9250 return getInput(btnEx4, true, true);
9251 }
9252 bool DrunkrSbtn()
9253 {
9254 return getInput(btnS, true, true);
9255 }
9256 bool DrunkrMbtn()
9257 {
9258 return getInput(btnM, true, true);
9259 }
9260 6689226 bool DrunkrLbtn()
9261 {
9262 6689226 return getInput(btnL, true, true);
9263 }
9264 6685751 bool DrunkrRbtn()
9265 {
9266 6685751 return getInput(btnR, true, true);
9267 }
9268 bool DrunkrPbtn()
9269 {
9270 return getInput(btnP, true, true);
9271 }
9272
9273 9337 void eat_buttons()
9274 {
9275 9337 getInput(btnA, true, false, true);
9276 9337 getInput(btnB, true, false, true);
9277 9337 getInput(btnS, true, false, true);
9278 9337 getInput(btnM, true, false, true);
9279 9337 getInput(btnL, true, false, true);
9280 9337 getInput(btnR, true, false, true);
9281 9337 getInput(btnP, true, false, true);
9282 9337 getInput(btnEx1, true, false, true);
9283 9337 getInput(btnEx2, true, false, true);
9284 9337 getInput(btnEx3, true, false, true);
9285 9337 getInput(btnEx4, true, false, true);
9286 9337 }
9287
9288 // Is true for the _first frame_ of a key press.
9289 // But! it is possible that a script manually sets the value of KeyPress,
9290 // in which case it will be restored to the "true" value based on `key_current_frame`
9291 // and `key_previous_frame` on the next frame.
9292 14 bool zc_readkey(int32_t k, bool ignoreDisable)
9293 {
9294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(ignoreDisable) return KeyPress[k];
9295
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 switch(k)
9296 {
9297 case KEY_F7:
9298 case KEY_F8:
9299 case KEY_F9:
9300 return KeyPress[k];
9301
9302 default:
9303
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 return KeyPress[k] && !disabledKeys[k];
9304 }
9305 14 }
9306
9307 // Is true for _every frame_ a key is held down.
9308 // But! it is possible that a script manually sets the value of KeyInput,
9309 // in which case it will be restored to the "true" value based on `key_current_frame`
9310 // on the next frame.
9311 bool zc_getkey(int32_t k, bool ignoreDisable)
9312 {
9313 if(ignoreDisable) return KeyInput[k];
9314 switch(k)
9315 {
9316 case KEY_F7:
9317 case KEY_F8:
9318 case KEY_F9:
9319 return KeyInput[k];
9320
9321 default:
9322 return KeyInput[k] && !disabledKeys[k];
9323 }
9324 }
9325
9326 // Reads (and then clears) the current frame key state directly.
9327 // Scripts can also modify `key_current_frame`.
9328 303 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9329 {
9330
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 301 times.
303 if(zc_getrawkey(k, ignoreDisable))
9331 {
9332 2 _key[k]=key[k]=key_current_frame[k]=0;
9333 2 return true;
9334 }
9335 301 _key[k]=key[k]=key_current_frame[k]=0;
9336 301 return false;
9337 303 }
9338
9339 // Reads the current frame key state directly.
9340 // Scripts can also modify `key_current_frame`.
9341 63252960 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9342 {
9343
2/2
✓ Branch 0 taken 53965721 times.
✓ Branch 1 taken 9287239 times.
63252960 if(ignoreDisable) return key_current_frame[k];
9344
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9287239 times.
9287239 switch(k)
9345 {
9346 case KEY_F7:
9347 case KEY_F8:
9348 case KEY_F9:
9349 return key_current_frame[k];
9350
9351 default:
9352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9287239 times.
9287239 return key_current_frame[k] && !disabledKeys[k];
9353 }
9354 63252960 }
9355
9356 // Only used for a handful of keys, like tilde and Function keys.
9357 // This state is never read within the game.
9358 // It exists so that all keyboard input still functions during replay,
9359 // without inadvertently doing things like toggling throttling if the player
9360 // presses ~
9361 9287211 bool zc_get_system_key(int32_t k)
9362 {
9363 9287211 return key_system[k];
9364 }
9365
9366 // True for the _first_ frame of a key press.
9367 83584899 bool zc_read_system_key(int32_t k)
9368 {
9369 83584899 return key_system_press[k];
9370 }
9371
9372 1179475797 bool is_system_key(int32_t k)
9373 {
9374
2/2
✓ Branch 0 taken 1095890898 times.
✓ Branch 1 taken 83584899 times.
1179475797 switch (k)
9375 {
9376 case KEY_BACKQUOTE:
9377 case KEY_CLOSEBRACE:
9378 case KEY_END:
9379 case KEY_HOME:
9380 case KEY_OPENBRACE:
9381 case KEY_PGDN:
9382 case KEY_PGUP:
9383 case KEY_TAB:
9384 case KEY_TILDE:
9385 83584899 return true;
9386 }
9387 1095890898 return is_Fkey(k);
9388 1179475797 }
9389
9390 9287211 void update_system_keys()
9391 {
9392
2/2
✓ Branch 0 taken 1179475797 times.
✓ Branch 1 taken 9287211 times.
1188763008 for (int32_t q = 0; q < 127; ++q)
9393 {
9394
2/2
✓ Branch 0 taken 195031431 times.
✓ Branch 1 taken 984444366 times.
1179475797 if (!is_system_key(q))
9395 984444366 continue;
9396
9397 195031431 key_system[q] = key[q];
9398
1/2
✓ Branch 0 taken 195031431 times.
✗ Branch 1 not taken.
195031431 key_system_press[q] = key_system[q] && !key_system_previous[q];
9399 195031431 key_system_previous[q] = key_system[q];
9400 195031431 }
9401 9287211 }
9402
9403 10391501 void update_keys()
9404 {
9405
2/2
✓ Branch 0 taken 1319720627 times.
✓ Branch 1 taken 10391501 times.
1330112128 for (int32_t q = 0; q < 127; ++q)
9406 {
9407 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9408
1/2
✓ Branch 0 taken 1319720627 times.
✗ Branch 1 not taken.
1319720627 if (!replay_is_replaying())
9409 key_current_frame[q] = key[q];
9410
9411
2/2
✓ Branch 0 taken 1309932100 times.
✓ Branch 1 taken 9788527 times.
1319720627 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9412 1319720627 KeyInput[q] = key_current_frame[q];
9413 1319720627 key_previous_frame[q] = key_current_frame[q];
9414 1319720627 }
9415 10391501 }
9416
9417 bool zc_disablekey(int32_t k, bool val)
9418 {
9419 switch(k)
9420 {
9421 case KEY_F7:
9422 case KEY_F8:
9423 case KEY_F9:
9424 return false;
9425
9426 default:
9427 disabledKeys[k] = val;
9428 return true;
9429 }
9430 }
9431
9432 void zc_putpixel(int32_t layer, int32_t x, int32_t y, int32_t cset, int32_t color, int32_t timer)
9433 {
9434 timer=timer;
9435 particles.add(new particle(zfix(x), zfix(y), layer, cset, color));
9436 }
9437